【发布时间】:2021-02-10 05:13:29
【问题描述】:
我对 java 很陌生,在高中学习它的课程,我们刚开始使用简单的程序来熟悉语法,但由于某种原因,我无法使用 Scanner 将字符串输入字符串变量。这行代码只是被忽略了。我试过直接复制/粘贴他给我们的老师的笔记,即使在我的电脑上运行,它们也可以在他自己的程序中运行良好,但它们在我的程序中不起作用。我做错了什么?
import java.util.Scanner;
public class Control5
{
public static void main (String [] args)
{
Scanner input = new Scanner(System.in);
String job;
System.out.println("1");
int years;
System.out.print("How many years have you been employed here? ");
years = input.nextInt();
System.out.print("Enter your job title: ");
job = input.nextLine();
if ((years > 5) & (job.toLowerCase() == "salesman")) {
System.out.println("Eligible for promotion.");
}
else {
System.out.println("Not eligible for promotion.");
}
}
}
【问题讨论】: