0

Note: I need to clear the previous printed values in the console and need to position my cursor in [row][column]=0

System.out.println("Hello World");
System.out.println("Hello Country");
System.out.println("\033[0;0H"); //need to apply the escape sequence here
System.out.println("Happy:)");

Expected Output:

Happy:)
Hello Country

Am getting this output in this online compiler but not in other compilers

Gokul raj
  • 53
  • 5
  • no this is not duplicate of that, in my case, it is a completely different scenario. I have 7 small component installer I need to show the user something like Installing Component 1 then in the next line a loader with percentage if component 1 finished installing then I need to show Installing Component 2 by erasing the previous two printed lines in the console and it is same for the next 5 componenets. I have searched a lot but nothing works. But I can achieve this in C using the escape sequence, that's why am asking whether it is possible to achieve the same here or not. – Gokul raj May 21 '18 at 11:57
  • Ahh my bad sorry =) – IsThisJavascript May 21 '18 at 11:58
  • If you want to know how to clear the console; see @Steephen's link. If you want to output an arbitrary control character, use an octal escape (e.g. `\033`) or a Unicode escape (e.g. `\u001B`) in the character or string literal. – Stephen C May 21 '18 at 12:37

1 Answers1

-1

To get next line its just necesary add "\n":

System.out.println("\nHello World");
System.out.println("\nHello Country");
System.out.println("\nEsc[2J"); //need to apply the escape sequence here
System.out.println("\nHappy:)");
  • 1) The question is not about newlines. It is about how to output an ESC control code. 2) The `println` call adds an end-of-line at the end of the string, so adding another is wrong. 3) Outputting a `\n` is incorrect on Windows and on Mac OSX. On those platforms, the end-of-line sequences are different. – Stephen C May 21 '18 at 12:55