+ 5

Clear screen In Java

how can I clear screen in Java? Just like clrscr(); in C language

8th Apr 2017, 2:30 PM
Muhammad Ahmed
Muhammad Ahmed - avatar
7 Answers
+ 12
System.out.print('\f'); or System.out.print('\u000C');
8th Apr 2017, 2:58 PM
Tashi N
Tashi N - avatar
+ 11
You can use ANSI escape control sequence: System.out.print("\u001B[2J"); ... will clear the screen ( without replacing text cursor at top left corner ^^ ) This should work on console ( real local ) but not with the console output emulator of Slolearn code playground :( [ edit ] https://en.m.wikipedia.org/wiki/ANSI_escape_code
8th Apr 2017, 7:08 PM
visph - avatar
+ 8
That doesn't work if you use your console to run your program. Works in ide.
8th Apr 2017, 5:29 PM
Tashi N
Tashi N - avatar
+ 5
I just needed this in Python*, and ANSI clear does not home the cursor to (0,0); it just prints enough blank lines to clear content...continuing at the bottom: [ (cleared area) [ [ [ content prints at bottom [ scrolling up_ The entire ANSI command string should be: chr(27) + "[2J" + chr(27) + "[0;0H" This clears the screen (2J) and positions the print cursor at the top left (0;0H) so it prints downwards. * (not Windows. Printing chr(12) usually clears those terminals)
25th Apr 2017, 3:55 AM
Kirk Schafer
Kirk Schafer - avatar
+ 4
8th Apr 2017, 5:30 PM
Muhammad Ahmed
Muhammad Ahmed - avatar
+ 3
not working :(
8th Apr 2017, 5:28 PM
Muhammad Ahmed
Muhammad Ahmed - avatar
Tashi n fuck u when you dont know anything then why you post anything you motherfucking piece of shit . piece of cow dung.Just imagine if your dad used a condem and you were not even born. This earth would have been very peaceful you whore
18th May 2022, 9:18 AM
jaskarnvir singh