我是靠谱客的博主 现实鸵鸟,这篇文章主要介绍第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder)第二章第二题(计算圆柱体的体积)(Compute the volume of a cylinder),现在分享给大家,希望可以做个参考。
第二章第二题(计算圆柱体的体积)(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内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复