2015-12-22 37 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