java Switch语句在我的ifelse语句之后被忽略
//Scanner
Scanner scan = new Scanner(System.in);
//Variables
double bmi; // Body Mass Index
double weight; // Weight in kilograms
double height; // Height in meters
String[] classification = {"Underweight", "Normal", "Overweight", "Obese"};
System.out.print("Your weight in KG \n");
weight = scan.nextDouble();
System.out.print("Enter height in meters: \n");
height = scan.nextDouble();
bmi = weight / (height * height);
if (bmi < 18.5) {
System.out.print("You're " + classification[0] + "\n");
} else if (bmi < 25) {
System.out.print("You're " + classification[1] + "\n");
} else if (bmi < 30) {
System.out.print("You're " + classification[2] + "\n");
} else {
System.out.print("You're " + classification[3] + "\n");
}
switch (Arrays.toString(classification)) {
case "Underweight":
System.out.println("Underweight");
break;
case "Normal":
System.out.println("Normal");
break;
case "Overweight":
System.out.println("A bit overweighted");
break;
case "Obese":
System.out.println("A bit obese");
break;
default:
System.out.println("Ok");
break;
}
}
输出,,my switch语句在if-else语句之后不起作用。它会忽略所有内容,并直接跳转到我的开关中的默认值。而我的意图是在if-else之后再写一些文字。所以基本上,如果我的计算结果显示我超重了,那么我的switch语句现在必须跳转到case“overweighted”并打印出那段代码。。我做错了什么
共 (0) 个答案