|
package xiangmu;
|
|
|
|
public class Ceshi {
|
|
public static void main(String args[]) {
|
|
// 计算圆的面积和周长
|
|
double r = 3;
|
|
final double PI = 3.14159; // 命名常量,一次赋值,不可更改
|
|
double mianji = PI * r * r;
|
|
System.out.println("面积为:" + String.format("%.3f", mianji)); // 保留三位小数
|
|
double zhouchang = 2 * PI * r;
|
|
System.out.println("周长为:" + String.format("%.3f", zhouchang));
|
|
}
|
|
}
|