简体   繁体   中英

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.

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. 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. For example:

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

The \\n is a special character. Whenever you see a leading backslash with a character is means it does something special. \\n means to go to the next line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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