定义宏常量:public static final double PI = 3.14159;
结果保留两位小数String.format("%.2f",number)
import java.util.Scanner; public class Main { public static final double PI = 3.14159; public static void main(String[]args){ Scanner sc = new Scanner(System.in); double r,h,s; r= sc.nextDouble(); h= sc.nextDouble(); s=2*PI*r*h+2*PI*r*r; System.out.print(String.format("%.2f",s)); } }