【发布时间】:2013-06-09 17:36:36
【问题描述】:
我的第二个扫描仪输入按需要存储,但仍然没有执行比较正确字符串 == stringValue 的 if 条件。 你能帮忙吗?
{
static String stringValue = "A";
public static void main(String[] args) {
int time;
time = speedType();
//System.out.println(time);
}
private static int speedType() {
System.out.println("Let's play a game\nHow fast can you type \"I type very quickly\" \nPress Enter then type the statement and then press Enter again");
Scanner scanner = new Scanner (System.in);
String string = scanner.nextLine();
if(string.equals("")){
Date startTime = new Date();
System.out.println("Start:\n");
String correctString = scanner.nextLine();
System.out.println(correctString);
if (correctString == stringValue){
Date endTime = new Date();
System.out.println(endTime);
}
else
System.out.println("Please enter correct string");
}
return 0;
}}
【问题讨论】:
-
你在这里做对了
string.equals("")在这里做错了if (correctString == stringValue){... -
今天是
==的国庆日吗? -
@MarounMaroun 它是所有的日子......
-
他们应该让 == 在 java9 中的字符串上做 .equals。
标签: java loops if-statement java.util.scanner