-1

How to clear the screen in the Java loke clrscr() command in c.

I am use the command prompt to run the program.

Please put the code:

class Demo
{
    public static void main(String[] s)
    {
        //clear scrren hear
        System.out.println("Hello World");
    }
}

Also use Runtime class but thats not work pls give the same code to perform this.

Also using this code but not work:

     import java.io.*;  
       class demo
{
    public static void main(String[] s)
    {   
        try
{
    String os = System.getProperty("os.name");

    if (os.contains("Windows"))
    {
        Runtime.getRuntime().exec("cls");
    }
    else
    {
        Runtime.getRuntime().exec("clear");
    }
}
catch (Exception exception)
{
}
        //clear scrren hear
        System.out.println("Hello World");
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Hiren Raiyani
  • 754
  • 2
  • 12
  • 28

1 Answers1

0

This could work

Console console = System.console();        
console.clear();
krish
  • 537
  • 2
  • 14