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+".");
}
}
答案 0 :(得分:3)
2个错误
1)它是String
而非string
2)double.parsedouble
不正确它应该是Double.parseDouble
不要忘记java是case sensitive
,方法名称有camel case
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+".");
}
}
答案 1 :(得分:0)
您可能希望使用Double.parseDouble(input)
代替double.parsedouble(input)
。
答案 2 :(得分:0)
尝试
Double.parseDouble(0.0);
使用Double
作为对象,而不是基元。对对象的调用返回原语double
。
答案 3 :(得分:0)
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+".");
}
}
答案 4 :(得分:0)
我认为您的代码应如下所示: import javax.swing。*;
public class CandidateCode
{
public static void main (String[] args)
{
String input;
input=JOptionPane.showInputDialog("What is the radius of the cylinder?");
double r=Double.parseDouble(input);
input=JOptionPane.showInputDialog("What is the height of the cylinder?");
double h=Double.parseDouble(input);;
double pi=3.1415926535;
double volume=pi*r*r*h;
System.out.println("The volume of the cylinder is: "+volume+".");
}
}
我对它做了一些改变。
String
而非string
。Double
类,因为double
是原始类型。