Following is the code to clear screen using Java −
Example
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.