关于java写法有效数字取法的求教!
查看原帖
关于java写法有效数字取法的求教!
357238
Rayesl楼主2020/9/25 23:14

代码通过了,但是感觉自己用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");
		 }
	}
}
2020/9/25 23:14
加载中...