How to Clear the Screen in Java

Open the IDE., Copy and paste the following code: class Clear { public static void main(String[] args) { System.out.print("\f"); System.out.print("Hello there !, Run the program., Understand what the program does.

4 Steps 1 min read Easy

Step-by-Step Guide

  1. Step 1: Open the IDE.

    Open your IDE of choice, or use write and then run the code through the Command Prompt. ,"); } } , The output will be Hello there !.

    Also it will clear the console before typing out the message., Once you understand how it works, you can use the same method in other contexts more easily.

    First it inserts a new form-feed due to escape sequence "\f"

    thereby clearing the screen.

    Then, it prints out the message :
    Hello there !
  2. Step 2: Copy and paste the following code: class Clear { public static void main(String[] args) { System.out.print("\f"); System.out.print("Hello there !

  3. Step 3: Run the program.

  4. Step 4: Understand what the program does.

Detailed Guide

Open your IDE of choice, or use write and then run the code through the Command Prompt. ,"); } } , The output will be Hello there !.

Also it will clear the console before typing out the message., Once you understand how it works, you can use the same method in other contexts more easily.

First it inserts a new form-feed due to escape sequence "\f"

thereby clearing the screen.

Then, it prints out the message :
Hello there !

About the Author

J

Joan Nguyen

Enthusiastic about teaching pet care techniques through clear, step-by-step guides.

52 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: