import java.text.DecimalFormat;
import java.util.Scanner;
public static String forMale(double h) {
DecimalFormat df = new DecimalFormat("0.00");
return df.format((h - 100) * 0.9);
}
//计算男性标准体重的方法
public static String forFemale(double h) {
DecimalFormat df = new DecimalFormat("0.00");
return df.format((h - 100) * 0.9 - 2.5);
}
}
public class StdWeightTest {
public static void main(String[] args) {
//创建键盘录入对象
Scanner sc = new Scanner(System.in);
//提示输入身高
System.out.println("请输入你的身高(cm):");
double height = sc.nextInt();
//提示输入性别
System.out.println("请输入你的性别:");
String sex = sc.next();
//根据性别调用不同方法
switch (sex) {
case "男":
System.out.println("你的标准体重(kg):"+StdWeight.forMale(height));
break;
case "女":
System.out.println("你的标准体重(kg):"+StdWeight.forMale(height));
break;
default:
System.out.println("你输入的有误!!");
}
}
}
import java.util.Scanner;
class StdWeight {
public static String forMale(double h) {
DecimalFormat df = new DecimalFormat("0.00");
return df.format((h - 100) * 0.9);
}
//计算男性标准体重的方法
public static String forFemale(double h) {
DecimalFormat df = new DecimalFormat("0.00");
return df.format((h - 100) * 0.9 - 2.5);
}
}
public class StdWeightTest {
public static void main(String[] args) {
//创建键盘录入对象
Scanner sc = new Scanner(System.in);
//提示输入身高
System.out.println("请输入你的身高(cm):");
double height = sc.nextInt();
//提示输入性别
System.out.println("请输入你的性别:");
String sex = sc.next();
//根据性别调用不同方法
switch (sex) {
case "男":
System.out.println("你的标准体重(kg):"+StdWeight.forMale(height));
break;
case "女":
System.out.println("你的标准体重(kg):"+StdWeight.forMale(height));
break;
default:
System.out.println("你输入的有误!!");
}
}
}