简体   繁体   English

Eclipse 不会将多行代码打印到控制台

[英]Eclipse won't print multiple lines of code to the console

I'm trying to write an example program to help me better understand java but the problem is Eclipse will only print out whatever is in System.out.println() for one line of code and not all of them.我正在尝试编写一个示例程序来帮助我更好地理解 java,但问题是 Eclipse 只会打印出System.out.println()中的一行代码而不是所有代码。

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
        }
    }

Eclipse doesn't flag up anything as being wrong and I don't get any errors when printing to the console it's just that my second and third lines of code print nothing to the console for whatever reason. Eclipse 不会将任何错误标记为错误,并且在打印到控制台时我没有收到任何错误,只是我的第二行和第三行代码无论出于何种原因都没有向控制台打印任何内容。 I removed some single and multi line comments from the text but the code remains unedited in the pictures thanks for the help and sorry if my code looks confusing.我从文本中删除了一些单行和多行注释,但图片中的代码仍未编辑,感谢您的帮助,如果我的代码看起来令人困惑,请见谅。

Simply use \\n after you finish with your message.完成消息后只需使用\\n For example:例如:

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

The \\n is a special character. \\n是一个特殊字符。 Whenever you see a leading backslash with a character is means it does something special.每当您看到带有字符的前导反斜杠时,就意味着它做了一些特别的事情。 \\n means to go to the next line. \\n表示转到下一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM