- 输入一个性别、身高和体重值,输出其形体状态(太轻、标准、太重)。
- 男性标准体重值(kg)=
- 身高>=165cm:身高(cm)-100
- 身高<165cm:身高(cm)-105
- 女性标准体重值(kg)= 身高(cm)-100
package com.xintouyun.xunhuan.test1; import java.util.Scanner; public class XunhuanTest2 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("请输入身高"); double height=sc.nextInt(); System.out.println("请输入体重"); double weight=sc.nextInt(); System.out.println("请输入性别(male/female)"); String sex=sc.next(); String bodyzt=getbody(height,weight,sex); System.out.println("您输入的身体状态评定为:"+bodyzt); } public static String getbody(double height,double weight,String sex){ if(sex=="male"){ if(height>=165){ if(weight<=(height-100)*1.02&&weight>=(height-100)*0.98){ return"体重标准"; } else if(weight>(height-100)*1.02){ return"体重太重"; } else if(weight<(height-100)*0.98){ return"体重太轻"; } } else if(height>0&&height<165){ if(weight<=(height-105)*1.02&&weight>=(height-105)*0.98){ return"体重标准"; } else if(weight>(height-105)*1.02){ return"体重太重"; } else if(weight<(height-105)*0.98){ return"体重太轻"; } } } else{ if(weight<=(height-100)*1.02&&weight>=(height-100)*0.98){ return"体重标准"; } else if(weight>(height-100)*1.02){ return"体重太重"; } else if(weight<(height-100)*0.98){ return"体重太轻"; } } return "输入无效的值"; } }
package com.xintouyun.xunhuan.test1;
import java.util.Scanner;
public class XunhuanTest2 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入身高");
double height=sc.nextInt();
System.out.println("请输入体重");
double weight=sc.nextInt();
System.out.println("请输入性别(male/female)");
String sex=sc.next();
String bodyzt=getbody(height,weight,sex);
System.out.println("您输入的身体状态评定为:"+bodyzt);
}
public static String getbody(double height,double weight,String sex){
if(sex=="male"){
if(height>=165){
if(weight<=(height-100)*1.02&&weight>=(height-100)*0.98){
return"体重标准";
}
else if(weight>(height-100)*1.02){
return"体重太重";
}
else if(weight<(height-100)*0.98){
return"体重太轻";
}
}
else if(height>0&&height<165){
if(weight<=(height-105)*1.02&&weight>=(height-105)*0.98){
return"体重标准";
}
else if(weight>(height-105)*1.02){
return"体重太重";
}
else if(weight<(height-105)*0.98){
return"体重太轻";
}
}
}
else{
if(weight<=(height-100)*1.02&&weight>=(height-100)*0.98){
return"体重标准";
}
else if(weight>(height-100)*1.02){
return"体重太重";
}
else if(weight<(height-100)*0.98){
return"体重太轻";
}
}
return "输入无效的值";
}
} -
运行结果:
- 男性标准体重值(kg)=
转载自原文链接, 如需删除请联系管理员。
原文链接:输入一个性别、身高和体重值,输出其形体状态(太轻、标准、太重),转载请注明来源!