View Single Post
  #1 (permalink)  
Old 08-06-2007, 12:52 AM
carl carl is offline
Member
 
Join Date: Jul 2007
Posts: 35
carl is on a distinguished road
Help with if statement
Hi, whenever I enter y or Y and call the method it should print out OK, but it doesn't it skips all the else if's and executes the last else statement "terminating" any suggestions why?I included the import java.lang.String
Code:
public void checkVariable() { if(checkString == "y" || checkString == "Y") { System.out.println("OK"); } else if(checkString == "yes" || checkString == "Yes") { System.out.println("OK"); } else if(checkString == "ok" || checkString == "OK") { System.out.println("OK"); } else if(checkString == "sure" || checkString == "Sure") { System.out.println("OK"); } else if(checkString == "why not?" || checkString == "Why not?") { System.out.println("OK"); } else if(checkString == "n" || checkString == "N" || checkString == "no" || checkString == "No") { System.out.println("OK"); } else { System.out.println("Terminating"); } }
Thanks.
Reply With Quote
Sponsored Links