我正在为学校做一些实验练习。以下代码适用于薪资等级计算器。我在第一轮的控制台中看到一些奇怪的东西,一切正常,但如果有第二轮输入数据,则跳过必须输入名称的部分。
我已经包含了代码,以及下面的屏幕截图。有人可以帮助我吗?
import java.util.*;
public class readSalary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
int salary, meritPoints;
String[] grade = {"A","B","C"};
int terminator = 0;
while (terminator == 0) {
System.out.println("Enter Name \n");
name = sc.nextLine();
System.out.println("Enter Salary \n");
salary = sc.nextInt();
System.out.println("Enter Merit Points \n");
meritPoints = sc.nextInt();
if (salary > 600 && salary < 649) {
if (meritPoints < 10) {
System.out.println("Employee: "+name+" has a grade of: "+grade[2]);
}
else {
System.out.println("Employee: "+name+" has a grade of: "+grade[1]);
}
}
else if (salary > 700 && salary < 900) {
if (meritPoints < 20) {
System.out.println("Employee: "+name+" has a grade of: "+grade[1]);
}
else {
System.out.println("Employee: "+name+" has a grade of: "+grade[0]);
}
}
System.out.println("Type 1 to Quit, or 0 to Continue \n");
terminator = sc.nextInt();
if (terminator == 0) {
terminator = 0;
}
else {
terminator = 1;
}
}
sc.close();
}
}
屏幕截图如下:
谢谢!