几年前参加完类(class)后,我刚刚买了一本关于 Java 编码的书。我决定开始编写一个程序来恢复正常状态。无论如何,我计算圆柱体积的程序有问题。您能批评一下并告诉我发生了什么事吗?如果有任何帮助,我正在使用 JCreator。
import javax.swing.*;
public class Cylinder_Volume
{
public static void main (String[] args)
{
string input;
input=JOptionPane.showInputDialog("What is the radius of the cylinder?");
double r;
r=double.parsedouble(input);
input=JOptionPane.showInputDialog("What is the height of the cylinder?");
double h;
h=double.parsedouble(input);
double pi=3.1415926535;
double volume=pi*r*r*h;
System.out.println("The volume of the cylinder is: "+volume+".");
}
}
最佳答案
2 个错误
1) 它是字符串
而不是字符串
2) double.parsedouble
不正确,应该是 Double.parseDouble
不要忘记java是区分大小写
并且方法名称具有驼峰式大小写
import javax.swing.*;
public class Cylinder_Volume
{
public static void main (String[] args)
{
String input;//first error you have types string //s should be capital
input=JOptionPane.showInputDialog("What is the radius of the cylinder?");
double r;
r=Double.parseDouble(input);//2nd problem
input=JOptionPane.showInputDialog("What is the height of the cylinder?");
double h;
h=Double.parseDouble(input);
double pi=3.1415926535;
double volume=pi*r*r*h;
System.out.println("The volume of the cylinder is: "+volume+".");
}
}
关于java - 我在字符串到 double 转换中做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27644510/