无法在命令行中编译程序但是在Eclipse上工作?

时间:2015-02-10 12:37:29

标签: java

我有两个类:我无法让它们中的任何一个在命令行中编译:我正在使用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);
    }
}

1 个答案:

答案 0 :(得分:6)

添加class关键字

public class SodaCan {