How to clear screen using Java?

JavaObject Oriented ProgrammingProgramming

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.

raja
Published on 04-Jul-2020 10:43:35
Advertisements