Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (mokeira):

Look at this simple Hello World program public class Test { public static void main(String[] args) { System.out.print("Hello"); System.out.println("World"); } } So, it will print this: HelloWorld I don't understand why it wont print Hello World because "World" has println and not print...someone kindly explain

OpenStudy (woodrow73):

Hello Mokeira.

OpenStudy (mokeira):

hello @woodrow73

OpenStudy (woodrow73):

Let me explain the difference between the print and println methods. First, I'll follow the logic of your main method body; System.out.print("Hello"); //this prints Hello in the console System.out.println("World"); //this prints World on the same line, //however, after the println is sent to the console, the invisible cursor is sent to the next line So println will print on whatever line the cursor is currently on, and after it prints, the cursor will be sent to the next line. I'll show you some examples of this in play: System.out.println("Hello"); //prints hello to the line, then cursor gets sent //down one line System.out.print("World"); //Cursor is on the line below hello, and now "world" //is printed. Another example to see their logic in play: System.out.print("Hello, "); System.out.print("I display next to hello. "); System.out.println("I display on the same line, and am the last to display on this line"); System.out.println("I am on the 2nd line. after this prints, " + "the cursor is sent to the line below this one."); System.out.print("I'm on the bottom."); Console will output the following: Hello, I display next to hello. I display on the same line....ect I am on the 2nd line. after this prints, the cursor will be sent below I'm on the bottom.

OpenStudy (woodrow73):

make sense?

OpenStudy (mokeira):

totally! Thanks @woodrow73 i like how you choose to look at t so

OpenStudy (mokeira):

Makes it so simple to understand

OpenStudy (woodrow73):

Thanks, mokeira.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!