2015-12-22 62 views
-3

我是新來的這個網站,我想寫一個示例程序來幫助我更好地理解java,但問題是Eclispe只會打印出任何內容對於一行代碼而言並非全部都是System.out.println()eclispe不會打印多行代碼到控制檯

class MyClass { 
    public static void main(String[] args){ 
     System.out.println("I am learning Java"); 
     System.out.println("Hello World");  

     String fruit = "apple";  
     int sea =1;     
     double goaldifference = 2.54; 

     System.out.println(fruit); 
     System.out.println(sea); 
     System.out.println(goaldifference); 

    } //this line of code is printed to the console 

    { 
     int a , b , c;   
     a =4; 
     b =6; 
     c = a+b; 
     System.out.println(c); 

     int hen =17;    
     System.out.println(++hen);      
    }//this line of code isn't printed to the console 

    {       
     int test = 6;     

     if (test == 9){ 
      System.out.println("yes"); 
     }else{ 
      System.out.println("no"); 
      if (test != 8){         
       System.out.println("no");       
      }else{           
       System.out.println("try different number"); 
      } 

      int age = 14; 

      if(age < 16){ 
       System.out.println("still in high school"); 
      }else if (age > 16){ 
       System.out.println("in college"); 
      }//this line of code isn't printed to the console 

     } 
    } 

Eclispe的不會標記任何東西作爲錯了,我沒有得到任何錯誤打印到它的控制檯時只是我的代碼打印什麼二,三線控制檯無論出於何種原因。我從文本中刪除了一些單行和多行的註釋,但代碼在圖片中保持未編輯狀態,感謝您的幫助,如果我的代碼看起來很混亂,我會很抱歉。

+0

對不起,我參考了任何圖片,我試圖包括eclispe的代碼的一些圖片,但網站不會讓我包括我想要的數字,所以我只是刪除它們 – Ronaldo

+1

你有一些額外的花括號,所以不是所有是你主要方法的一部分。 –

+0

只有主方法內部的SOP語句會被執行,因爲根據你的代碼,其他SOP語句不在主方法內部,而是在實例塊內部。順便說一句代碼將編譯和運行良好。 – user0946076422

回答

-2

在完成留言後,只需使用\n即可。例如:

System.out.println("First line\n"); 
System.out.println("Next line\n"); 

\n是一個特殊字符。只要你看到一個帶有字符的反斜槓,就意味着它做了一些特殊的事情。 \n意味着去下一行。

+0

'System.out.println();'它自己有'\ n' –

+0

啊我明白了。感謝您清除困惑.. – user5705625

+0

可能請詳細解釋我到底在哪裏使用System.out.println(「第一行\ n」); System.out.println(「下一行\ n」);在我的代碼 – Ronaldo