single
Printing Output
Swipe to show menu
Java provides two main ways to display output on the screen: print() and println(). While both are used to print text, the key difference is how they handle moving to a new line.
The most commonly used method is System.out.println(). It prints the text and automatically moves the cursor to the next line. This makes the output clean and easy to read, especially when printing multiple lines.
Main.java
12345678package com.example; public class Main { public static void main(String[] args) { System.out.println("Hello"); System.out.println("World"); } }
On the other hand, System.out.print() prints text but does not move to a new line. Instead, everything continues on the same line.
Main.java
12345678package com.example; public class Main { public static void main(String[] args) { System.out.print("Hello "); System.out.print("World"); } }
This difference becomes very important when you start controlling how your output is formatted. In most beginner cases, println() is preferred because it automatically organizes output in a readable way.
Swipe to start coding
Replace the line //replace this line with your code with the code that will display Hello World! on the screen.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat