2014-09-04 60 views
-6

我无法获得公共代码构造函数的正确语法。因此,这是主要的:正确的语法

public class Main_code { 

    public static void main(String[] args) { 

     Code C = new Code; 
     C.code(); 
     C.make(); 
    } 
} 

这是市民代码:

public class code { 

    int x; 
    int numbers; 
    int [] result; 

这是构造:

public code(){ 

    this.x=0; 
    this.numbers [] = {6, 3, 8, 9, 1, 4, 7}; 
    this.result= new int[x]; 
} 

最后,这是无效:

public void make(){ 

     for (int i=0; i<numbers.lenght){ 
      if(this.numbers[i]<5){ 
       this.result [x] = this.numbers[i] 
      } 
     } 
     for (int e=0; e<this.result.length;e++){ 
      System.out.println (this.result[e]); 
     } 
    } 
+0

向我们显示您收到的错误消息。告诉我们你的想法是什么意思。 – pamphlet 2014-09-04 21:30:24

+0

“大写的C代码应该是小写的”代码“吗?因为它们是不同的标识符 – khelwood 2014-09-04 21:34:15

回答

1
this.numbers [] = {6, 3, 8, 9, 1, 4, 7}; 

是无效的,numbersint类型,而不是一个数组

,即使它是一个数组,你就去做

this.numbers = new int[] {6, 3, 8, 9, 1, 4, 7}; 
0

您创建一个新的实例时忘记括号。而不是Code c = new Code;Code c = new Code(); //<-added brackets。此外,Java区分大小写,因此您必须将类和构造函数的名称更改为Code,否则java将不会识别Main_code类中的构造函数。你应该阅读通过java namig conventions,只是为了一个更清洁的代码。