Is there any way to clear the screen without cycling with '\ n'?

1

I would like to know if there are other possibilities besides for example running a series of '\ n'.

public void clrscrn(){
    for (int i = 0; i < 50; ++i) 
        System.out.println();
}
    
asked by anonymous 19.04.2017 / 22:01

1 answer

1

Two possibilities I know:

final String sisOpe = System.getProperty("os.name");

if (sisOpe.contains("Windows")){
    Runtime.getRuntime().exec("cls");

}else{
    Runtime.getRuntime().exec("clear");
}

or

System.out.print("\u001b[2J");
System.out.flush();
    
19.04.2017 / 22:30