概述
第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)
-
2.2(计算圆柱体的体积)编写程序,读入圆柱体的半径和高,并使用下列公式计算圆柱的体积:
面积 = 半径 × 半径 × π
体积 = 面积 × 高
下面是一个运行示例:
Enter the radius and length of a cylinder:5.5 12
The area is 95.0331
The volume is 1140.42.2(Compute the volume of a cylinder) Write a program that reads the radius and length of a cylinder and computes the area and volume using the following formulas:
area = radius × radius × π
volume = area × length
Here is a simple run:
Enter the radius and length of a cylinder:5.5 12
The area is 95.0331
The volume is 1140.4 -
参考代码:
package chapter02;
import java.util.*;
public class Code_02 {
public static void main(String[] args) {
double RadiusCylinder, LengthCylinder, AreaCylinder, VolumeCylinder;
System.out.print("Enter the radius and length of a cylinder : ");
Scanner R_L_input = new Scanner(System.in);
RadiusCylinder = R_L_input.nextDouble();
LengthCylinder = R_L_input.nextDouble();
AreaCylinder = RadiusCylinder * RadiusCylinder * Math.PI;
VolumeCylinder = AreaCylinder * LengthCylinder;
System.out.println("The area is " + AreaCylinder);
System.out.println("The volume is " + VolumeCylinder);
R_L_input.close();
}
}
- 结果显示:
Enter the radius and length of a cylinder : 5.5 18
The area is 95.03317777109125
The volume is 1710.5971998796424
Process finished with exit code 0
最后
以上就是现实鸵鸟为你收集整理的第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)的全部内容,希望文章能够帮你解决第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复