嘿伙计我只是搞乱了,我不能让这个工作:
public static void main(String[] args){
Scanner input = new Scanner (System.in);
String x = "hey";
System.out.println("What is x?: ");
x = input.nextLine();
System.out.println(x);
if (x == "hello")
System.out.println("hello");
else
System.out.println("goodbye");
}
Run Code Online (Sandbox Code Playgroud)
它当然应该打印你好hello如果你输入你好,但它不会.我正在使用Eclipse来搞砸.请快点帮忙
应该if (x.equals("hello")).
使用java对象,==用于参考比较..equals()用于价值比较.