import java.util.Scanner;
public class Exp2_4{
public static void main(String args[]){
char[] erqi={'M','F'};
System.out.print("您的性别是(M/F):");
Scanner reader=new Scanner(System.in);
char er=reader.next().charAt(0);
System.out.print("请输入你的身高:");
Scanner reader1=new Scanner(System.in);
float qi=reader.nextFloat();
System.out.print("请输入你的体重:");
Scanner reader2=new Scanner(System.in);
int xin=reader.nextInt();
float BMI=xin/qi/qi;
switch(er){
case 'M':
if(BMI<19)
System.out.println("你的体型过轻!");break;
if(BMI<24||BMI>19)
System.out.println("你的体型适中!");break;
if(BMI<29||BMI>24)
System.out.println("你的体型过重!");break;
if(BMI<34||BMI>29)
System.out.println("你的体型肥胖!");break;
case 'F':
if(BMI<20)
System.out.println("你的体型过轻!");break;
if(BMI<25||BMI>20)
System.out.println("你的体型适中!");break;
if(BMI<30||BMI>25)
System.out.println("你的体型过重!");break;
if(BMI<35||BMI>30)
System.out.println("你的体型肥胖!");break;
}
}
}

Switch语句出现错误
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注
public static void main(String[] args) { System.out.print("您的性别是(M/F):"); Scanner reader=new Scanner(System.in); char er=reader.next().charAt(0); System.out.print("请输入你的身高:"); Scanner reader1=new Scanner(System.in); float qi=reader.nextFloat(); System.out.print("请输入你的体重:"); Scanner reader2=new Scanner(System.in); int xin=reader.nextInt(); float BMI=xin/qi/qi; switch(er){ case 'M': if(BMI<19){ System.out.println("你的体型过轻!");break;} else if(BMI<24||BMI>19){ System.out.println("你的体型适中!");break;} else if(BMI<29||BMI>24){ System.out.println("你的体型过重!");break;} else if(BMI<34||BMI>29){ System.out.println("你的体型肥胖!");break;} case 'F': if(BMI<20){ System.out.println("你的体型过轻!");break;} else if(BMI<25||BMI>20){ System.out.println("你的体型适中!");break;} else if(BMI<30||BMI>25){ System.out.println("你的体型过重!");break;} else if(BMI<35||BMI>30){ System.out.println("你的体型肥胖!");break;} } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报