我不懂主要课程

时间:2014-10-12 21:45:55

标签: java

我一直在使用BlueJ来学习使用Java的编程,使用书籍#34; Objects First with Java"作者:David Barnes和Michael Kolling。我发现了一些我似乎无法在非BlueJ编译器中工作的练习题。例如,代码在Eclipse中抛出错误。

我为每一个问题创建了一个新课程"解决"如果我在BlueJ中运行它可以正常工作但我无法在Eclipse或任何其他站点中运行它而没有问题。

示例是此代码应该返回教师的成绩。

 public class Problem1 {

 public void betyg(int a, int b, int c, int d, int e, int rätt){
     if(rätt >= a) System.out.println( "A");
     if(rätt < a && rätt >= b) System.out.println( "B");
     if(rätt < b && rätt >= c) System.out.println( "C");
     if(rätt < c && rätt >= d) System.out.println( "D");
     if(rätt < d && rätt >= e) System.out.println( "E");
     else System.out.println( "F");
 }

}

当我在Eclipse中运行时,甚至没有任何事情发生。非常感谢任何和所有的帮助!

编辑: 这是我项目中的另一个课程。 我知道我需要这个才能使它工作,因为这是起点&#34;我的节目。但是如何让它运行我的问题1&#34;班级及其方法&#34; betyg&#34;?

 public class Main {

 public static void main(String[] args) {

        Problem1 test1 = new Problem1();        
 }
}

1 个答案:

答案 0 :(得分:1)

BlueJ可以实例化任意对象并在其上运行任何方法 - 它是一个旨在帮助您入门的新手IDE。

Eclipse,Netbeans等。需要一个合适的“主类”,这是一个带有完全签名方法的类:

public static void main(String[] args) {
    Problem1 p = new Problem1();
    //Any other code here
}

如果班级没有(因为这个没有),那么它不是主类,也不会被视为主类。

相关问题