2015-02-06 41 views
0

得到打印我正在按照here上提到的教程並嘗試將結果打印到文檔中由語句System.out.println (node);所述的節點中。我在Netbeans IDE中幾乎完成了任務。這裏是我的代碼將NetBeans:節點結果未按照文檔

public class Node { 


      public class NodeClass{ 
       int fele; 
       Node next; 

       public NodeClass(){ 

        fele = 1; 
        next = null; 
       } 


       public NodeClass(int fele , Node next){ 

        this.fele = fele; 
        this.next = next; 
       } 

       public String toString(){ 
        return fele + ""; 
       } 
      } 


      NodeClass node = new NodeClass(1,null); 
      System.out.println(node); 





} 

這裏是相同的圖像:

enter image description here

誰能告訴我什麼我做錯了嗎?

回答

1

你不能直接在課堂上有指示。您必須將這些行放在主要方法中。

public static void main(String[] args) { 
    NodeClass node = new NodeClass(1,null); 
    System.out.println(node); 
} 

爲什麼內部類雖然?試試這個:

public class Node { 
    int fele; 
    Node next; 

    public Node() { 
     fele = 1; 
     next = null; 
    } 

    public Node(int fele, Node next) { 
     this.fele = fele; 
     this.next = next; 
    } 

    public String toString() { 
     return fele + ""; 
    } 

    public static void main(String[] args) { 
     Node node = new Node(1, null); 
     System.out.println(node); 
    } 
} 
相關問題