exercise2_2.java
来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 27 行
JAVA
27 行
import javax.swing.JOptionPane;
public class Exercise2_2 {
public static void main(String[] args) {
// Enter radius of the cylinder
String radiusString = JOptionPane.showInputDialog(null,
"Enter radius of the cylinder",
"Exercise2_2 Input", JOptionPane.QUESTION_MESSAGE);
// Convert string to double
double radius = Double.parseDouble(radiusString);
// Enter length of the cylinder
String lengthString = JOptionPane.showInputDialog(null,
"Enter length of the cylinder",
"Exercise2_2 Input", JOptionPane.QUESTION_MESSAGE);
// Convert string to double
double length = Double.parseDouble(lengthString);
double volume = radius * radius * 3.14159 *length;
System.out.println("The volume of the cylinder is " + volume);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?