代码通过了,但是感觉自己用DecimalFormat来保留有效数字是错误的,请各位大佬来分享一下保留有效数字的方法
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.text.DecimalFormat;
class Main{
public static void main(String[] args)throws Exception {
Scanner s = new Scanner(new BufferedInputStream(System.in));
DecimalFormat df =new DecimalFormat("##.####");
int a =s.nextInt();
double b =s.nextDouble();
double BMI = a/b/b;
if(BMI<18.5)
{
System.out.println("Underweight");
}
if(BMI>=18.5&&BMI<24)
{
System.out.println("Normal");
}
if(BMI>=24)
{
System.out.println(df.format(BMI));
System.out.println("Overweight");
}
}
}