2015-02-10 29 views
0

我有两个类:我不能让他们中的任何一个在命令行中编译:我使用的是javac SodaCan.java提示符,但它仍然不会编译,它会显示如下内容:“error:Class,interface或enum expected “双,sodaCan,getvolume等无法让程序在命令行中编译但在Eclipse上工作?

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); 
    } 
} 
+2

你是如何编制?发布确切的命令 – codeMan 2015-02-10 12:38:46

+1

从哪里编译? – Maroun 2015-02-10 12:38:49

+0

@codeMan打字“javac sodaCan.java” – 2015-02-10 12:40:12

回答

6

添加class关键字

public class SodaCan { 
+0

啊..我怎么忘了。 – 2015-02-10 12:40:36

+0

以及我没有看到:D虽然你是Java程序员,但你可以看到尖锐:D – Lrrr 2015-02-10 12:42:06

+1

eclipse如何编译? – BluesSolo 2015-02-10 12:45:26

相关问题