题目描述:
编写程序,计算半径为5.5的圆的面积和周长。
代码:
public class Circle {
public static void main(String[] args){
final double radius=5.5;
double girth = 2*Math.PI*radius;
//调用Math函数中的pow()方法实现数的平方;
double area = Math.PI*Math.pow(5.5,2);
System.out.println("The girth of the circle is: "+girth);
System.out.println("The area of the circle is: "+area);
}
}
运行示例:
TIPS:
Math.pow(a,b)方法实现数a的b次方。