Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Comments | Getting Started
Java Basics (Pdf Generation)
セクション 1.  7
single

single

bookComments

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

Hiding Code in From the Compiler

You can hide code from the compiler by commenting out the code.

Code comments are fragments that the compiler will not process.

You can comment out lines of code using the // symbols or enclose a specific fragment of text or code using /* */.

Why do We Need Comments?

  • Comments let you write notes to explain what parts of the code do. These notes are ignored by the computer but make the code easier to understand for yourself or others;

  • Comments can temporarily disable parts of your code. For instance, if you think a specific line is causing an error, you can comment it out (/* code fragment */) to test the program without that line;

  • Comments can be used to describe how your code works, making it easier to understand later or for others working with your code.

You saw an example of commenting in the previous chapter, where a comment was placed where the code was supposed to go.

Here's another example of how to use comments:

Main.java

Main.java

copy
123456789
package com.example; public class Main { public static void main(String[] args) { System.out.println("Message 1"); // System.out.println("Message 2"); System.out.println("Message 3"); } }

Only the first and third messages will be displayed here because the second part is commented out, so the compiler ignores it.

Now, let's take a look at an example of multi-line code commenting:

Main.java

Main.java

copy
123456789
package com.example; public class Main { public static void main(String[] args) { /* System.out.println("Message 1"); System.out.println("Message 2"); */ System.out.println("Message 3"); } }

As you can see, only the third message is displayed in the console because the first and second ones are commented out.

タスク

スワイプしてコーディングを開始

Your task is to identify the error and comment out the code fragment that contains it.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

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

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

セクション 1.  7
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt