Java 2.2(计算圆柱的体积)编写程序,读入圆柱体的半径和高,并使用下列公式计算圆柱体的体积:

面积 = 半径 x 半径 x p

体积 = 面积 x 高

 下面是一个运算示例:

Enter the radius and length of a cylinder(请输入圆柱的半径和高): 5.5   12

The area is 95.0331(它的面积是95.0331)

The volume is 1140.4(它的体积是1140.4)

package Second;

import java.util.Scanner;

public class Cylinder {

	public static void main(String[] args) {
		
		System.out.println("Enter the radius and length of a cylinder:");
		Scanner input = new Scanner(System.in);
        double radius = input.nextDouble();
        double length = input.nextDouble();
        double area = 0.0,volume = 0.0;
        area =  radius * radius * Math.PI ;
        volume = radius * radius * Math.PI * length;
        System.out.println("The area is:"+area);
        System.out.println("The volume is:"+ volume);
      }

}

 输出

Enter the radius and length of a cylinder:
5.5
12
The area is:95.03317777109125
The volume is:1140.398133253095

你可能感兴趣的:(几何学,java,eclipse)