编写程序,读人圆柱体的半径和高,并使用下列公式计算圆柱的体积
面积 =半径 x 半径 x p
体积 = 面积 X 高
代码如下:
import java.util.Scanner;
public class CylinderAreaVolume {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the radius and length of a cylinder");
double radius = input.nextDouble();
double length = input.nextDouble();
double area = radius * radius * 3.14159;
double volume = area * length;
System.out.println("The area is" + area + "The volume is" + volume);
}
}
运行结果: