Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Printing Output | Getting Started with Java
Practice
Projects
Quizzes & Challenges
Quizze
Challenges
/
Java Fundamentals: An Introductory Course

bookPrinting Output

Swipe um das Menü anzuzeigen

Main.java

Main.java

copy
123456789101112
package com.example; public class Main { public static void main(String[] args) { System.out.println("Hello, Java!"); System.out.println("Welcome to your first Java program."); System.out.println("Let's learn how to print output."); System.out.println("Line breaks are added automatically after each statement."); System.out.println("You can use escape characters like \\n for a new line and \\t for a tab."); } }

Learning to display output is one of the first steps in Java programming. The System.out.println statement is used to print text to the console. Each time you call System.out.println, the text inside the parentheses is printed, and the cursor moves to the next line. The text you want to display must be enclosed in double quotes, making it a string literal. For example, System.out.println("Hello, Java!"); prints the message and then starts a new line.

You can include special characters in your strings using escape sequences:

  • \n Creates a new line within the string;
  • \t Adds a horizontal tab;
  • \" Prints a double quote inside the string;
  • \\ Prints a backslash character.

These escape characters help you format your output more precisely.

Beginners sometimes make mistakes when printing output. A common error is forgetting the double quotes around the string, which will cause a compilation error. Another frequent issue is omitting the semicolon at the end of the statement. Also, remember that Java is case-sensitive, so writing system.out.println instead of System.out.println will not work. Always use the correct capitalization and punctuation to avoid these mistakes.

question mark

Which of the following lines will correctly print Hello, Java! to the console in Java?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 2
some-alt