【发布时间】:2012-11-27 18:28:25
【问题描述】:
我真的不明白为什么当我写“y”并按回车时,下面的程序没有显示任何内容。
import java.util.Scanner;
public class desmond {
public static void main(String[] args){
String test;
System.out.println("welcome in our quiz, for continue write y and press enter");
Scanner scan = new Scanner(System.in);
test = scan.nextLine();
if (test == "y") {
System.out.println("1. question for you");
}
}
}
【问题讨论】:
-
在
if中使用test.equals("y")
标签: java string if-statement