package javase9; import java.text.DecimalFormat; public class javase9_2 { static public void SimpleFormat(String pattern, double value){ DecimalFormat myFormat=new DecimalFormat(pattern); //实例化DecimalFormat对象 String put=myFormat.format(value); //进行数字格式化 System.out.println("圆的面积:"+value+" "+pattern+" "+put); } public static double GetRoundArea(double r){ return Math.PI*Math.pow(r,2); //求圆的面积 } public static void main(String[] args) { System.out.println(); SimpleFormat("圆的面积保留五位小数:"+"#.#####",GetRoundArea(2)); } }