我有这个:
Scanner input = new Scanner ( System.in );
int selection = input.nextInt();
if (selection == 1) {
System.out.println("Please enter a string: ");
String code = input.nextLine();
}
Run Code Online (Sandbox Code Playgroud)
但是,当它输入请输入字符串时,它不会要求任何输入.它只是进入程序的其余部分.
我有这个循环:
String cont = "";
while ( cont != "n" ) {
// Loop stuff
System.out.print("another item (y/n)?");
cont = input.next();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我输入"n"来停止循环时,它就会继续运行.怎么了?
java ×2