我有两个类:我无法让它们中的任何一个在命令行中编译:我正在使用javac SodaCan.java提示但它仍然不会编译,它会说:“错误:类,接口或枚举预期“为双倍,sodaCan,getvolume等。
public SodaCan{
private double sArea;
private double volume;
public SodaCan(double height, double radius){
getSurfaceArea(height);
getVolume(radius);
}
public double getSurfaceArea(double height, double radius){
sArea = 2*Math.PI * Math.pow(radius, 2) + 2 * Math.PI * radius * height;
return sArea;
}
public double getVolume(double height, double radius){
volume = Math.PI * Math.pow(radius, 2) * height;
}
}
和
import java.util.*;
public class testSodaCan{
public static void main(String[] args){
double height, radius;
Scanner s = new Scanner(System.in);
System.out.println("Please input the height of the can: ");
height = s.nextDouble();
System.out.println("Please input the width of the can: ");
radius = s.nextDouble();
SodaCan can = new SodaCan(height, radius);
}
}
答案 0 :(得分:6)
添加class关键字
public class SodaCan {