Q:

Java program to clear console screen

belongs to collection: Java Basic Programs

0

Java program to clear console screen

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will print a message and then clear a printed message from the screen and then print another message.

Program/Source Code:

The source code to clear the console screen is given below. The given program is compiled and executed successfully.

// Java program to clear console screen

public class Main {
  public static void main(String[] args) {
    System.out.print("Hello World");

    //Now clear console screen.
    System.out.print("\033[H\033[2J");
    System.out.flush();

    //Now print new message on console.
    System.out.print("Hello India");
  }
}

Output:

Hello India

Explanation:

In the above program, we created a public class Main. It contains a static method main(). The main() method is an entry point for the program. And, printed the "Hello World" message. Then we clear the console screen using the below statements:

    System.out.print("\033[H\033[2J");
    System.out.flush();

After that, we printed the "Hello India" message.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to sleep program execution for specif... >>
<< Java program to validate date and print weekday of...