【发布时间】:2012-10-04 00:30:49
【问题描述】:
我在网上看过,所有的教程/问题都指出了这一点。我不明白为什么这不起作用。任何帮助将非常感激。谢谢
import java.util.*;
public class test {
static Scanner userInput = new Scanner(System.in);
public static void main(String[] args) {
String textEntered = userInput.next();
if (textEntered == "hello") {
System.out.println("Hello to you too!");
}
}
}
我输入“hello”,但没有打印任何内容。我也试过 next() 和 nextLine();
【问题讨论】:
-
我在 sn-p 中没有看到 while 循环...你想为用户输入循环吗?
-
我一直在看一些在线 youtube 教程,他没有提到这一点,当我在网上查看时,大多数使用非常相似的代码,我没有意识到是 if 语句不起作用.此外,在实际代码中,它位于 while 循环中,我只是对其进行了简化,这就是为什么我错误地标记了循环。