Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Printing Output | Getting Started with Java
Java Fundamentals: An Introductory Course

bookPrinting Output

Deslize para mostrar o menu

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

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Seção 1. Capítulo 2
some-alt