Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Printing Output | Getting Started with Java
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Java Fundamentals: An Introductory Course

bookPrinting Output

Свайпніть щоб показати меню

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

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 2
some-alt