为什么我得到“缺陷”而不是“正常”?
给定三个数字:A、B 和 H。据医生报告:
任务:
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int units = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
int h = b - a;
if (h < a ){
System.out.println("Deficiency");
} else if (h > b) {
System.out.println("Excess");
} else if (h == 8){
System.out.println("Normal");
}
}
}
Run Code Online (Sandbox Code Playgroud)
你为什么不把它简化成这样?
Scanner input = new Scanner(System.in);
int tooLittle = input.nextInt();
int tooMuch = input.nextInt();
int hoursSlept = input.nextInt();
if (hoursSlept <= tooLittle ){
System.out.println("Deficiency");
} else if (hoursSlept >= tooMuch) {
System.out.println("Excess");
} else {
System.out.println("Normal");
}
Run Code Online (Sandbox Code Playgroud)
请注意,之间有什么不同tooMuch,并tooLittle没有任何与安娜多少睡觉。因此,您还需要提示输入该值。