Just looking at past exam papers and stumbled across the following question which doesn't make much sense to me:
The following piece of code is meant to greet the user in an appropriate manner:
public static void main( String[] args ) {
System.out.println("Enter a name");
String name = EasyIn.getString();
if (name == "" )
System.out.println("You must input a name");
else
System.out.println("Hello, " + name);
}
The question asks why the program may not do what the programmer intended. With a lack of a laptop at the moment (spilt drink on it!) I can't test the code with different inputs etc. From what I can tell, the only problem with it is that it doesn't ask the user for another input of name if it is blank, and just terminates the program. I'd use this as the answer, but it is brought up later on in the question directly which makes me think it isn't the answer they're looking for. Are there any other problems with the code?