When this is run and I enter "foo" for scanner the first if statement is false. Why does this happen?PHP Code:import java.util.Scanner;
public class test {
public static void main(String[] args) {
String testOne = "foo";
String testTwo = "foo";
Scanner scan = new Scanner(System.in);
System.out.print("Insert \"foo\" as a value for busted: ");
String busted = scan.next();
if (testOne == busted)
System.out.println("scanned string comparison is working");
else if (testOne == testTwo)
System.out.println("predefined string comparison is working");
else
System.out.println("String comparison is completely busted");
}
}


Reply With Quote


Bookmarks