Closed. This question is not reproducible or was caused by typos。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我是Java新手。我正在尝试制作一个程序,供用户输入一个国家/地区并返回该国家/地区的当前时间。我有以下代码:
当我输入“俄罗斯”或“菲律宾”时,它不会输出任何内容。知道为什么吗?
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我是Java新手。我正在尝试制作一个程序,供用户输入一个国家/地区并返回该国家/地区的当前时间。我有以下代码:
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.println("Enter a country: ");
String userCountryInput = userInput.nextLine();
if (userInput.equals("Philippines")) {
Date date1 = new Date();
System.out.println(date1);
}
if (userInput.equals("Russia")) {
TimeZone.setDefault(TimeZone.getTimeZone("UTC + 05:30"));
Date date2 = new Date();
System.out.println(date2);
}
}
当我输入“俄罗斯”或“菲律宾”时,它不会输出任何内容。知道为什么吗?
最佳答案
userCountryInput
是输入变量。 userInput
是用于获取输入的Scanner变量
if ("Philippines".equals(userCountryInput)) {
关于java - input.equals(“字符串在这里”)不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31291692/