是不是太胖了?
采用DecimalFormat
类实现格式化数字的方法
题目计算身体常数
以下是代码
import java.text.DecimalFormat;
import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args){
double s;
Scanner a = new Scanner(System.in);
int h = a.nextInt();
s = (h-100)*0.9*2;
DecimalFormat df = new DecimalFormat("#.0");
System.out.print(df.format(s));
/*i love zhangyan*/
}
}
简单方便。
求整数的平均值
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int d = s.nextInt();
int Sum = a+b+c+d;
double Average = (a+b+c+d)/4.0;
DecimalFormat df = new DecimalFormat("#.0");
System.out.print("Sum="+Sum+";Average="+df.format(Average));
/*i love zhangyan*/
}
}