-3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • sorry I made reference to any pictures I tried to include some pictures of the code from eclispe but the website wouldn't let me include the number that I wanted so I just removed them – 6502Assembly4NESgames Dec 22 '15 at 02:54
  • 1
    You have some extra curly braces so not everything is part of your main method. – Tot Zam Dec 22 '15 at 03:03
  • only the SOP statements which are inside the main method will be executed, as per your code other SOP statements are not inside the main method instead they are inside instance block. btw code will compile and run fine. – user0946076422 Dec 22 '15 at 03:36

1 Answers1

-2

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.