2.2 (计算圆柱体的体积)编写程序,读入圆柱体的半径和高,并使用下列公式计算圆柱体的体积:
面积 = 半径 ×半径 × PI
体积 = 面积 × 高
import java.util.Scanner;
public class cylinderVolume{
public static void main(String[] args){
Scanner inPut = new Scanner(System.in);
final double PI = 3.14159;
System.out.println("Enter the radius and length of a cylinder:");
//输入圆柱形的半径和高
double radius = inPut.nextDouble();
double length = inPut.nextDouble();
//计算面积
double area = PI*Math.pow(radius,2);//PI*radius*radius;
System.out.println("The area is "+area);
//计算体积
double volume = area*length;
System.out.println("The volume is "+volume);
}
}