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
Java Fundamentals: An Introductory Course

Printing Output

メニューを表示するにはスワイプしてください

Main.java

Main.java

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?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  2

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  2
some-alt