
-----------------------------------
Chinmay
Sun Jan 06, 2008 7:54 pm

Very Weird, it will take you 10 secs to solve
-----------------------------------
Why wouldnt this work?   :( 

 

void makeItemsList() {
   System.out.print ("Hello");
}

		try {
			System.out.print("Want me to say hello to you? Y/N   : ");
			BufferedReader br4 = new BufferedReader(new InputStreamReader(System.in));
			
			String decision;
			decision = br4.readLine();
			String decision1 = (decision.toUpperCase());
			System.out.println("\"" + decision1 + "\"");
			
			if (decision1 == "Y") {
				makeItemsList();
			}
			
		} catch (IOException u) {}



Why wouldnt this code execute makeItemsList();

-----------------------------------
Tony
Sun Jan 06, 2008 8:02 pm

RE:Very Weird, it will take you 10 secs to solve
-----------------------------------
Because decision1 is a String object and "Y" is _another_ String literal. If they don't point to the same memory location, they are not the same, although they could hold the same value.

To compare against values, you should use .equals()

-----------------------------------
Chinmay
Sun Jan 06, 2008 8:38 pm

Re: Very Weird, it will take you 10 secs to solve
-----------------------------------
oh yes i forgot, thx man  :D 

very forgetfull  :wink:
