How to clear screen using Java?


Following is the code to clear screen using Java −

Example

 Live Demo

public class Demo{
   public static void main(String[] args){
      System.out.print("\033[H\033[2J");
      System.out.flush();
   }
}

Output

The screen would be cleared

A class named Demo contains the main function. Here, the ANSI escape code is written, that clears the screen. The flush function resets the cursor to the top of the window screen.

Updated on: 04-Jul-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements