The trick behind this is that you are going to replace everything at all. Since you are using Console you won't be able to customize any one graphic node. So, chances are that you are going to write everything to re-write the output.
Note: I do not know the code to clear the screen as in C++ clrscr()
, so you can add that code yourself to remove previous characters.
Since you have the code to write everything, do it this way,
char zero = '0';
char one = '1';
char two = '2';
char three = '3';
char four = '4';
char five = '5';
char six = '6';
char seven = '7';
char eight = '8';
private void render() {
System.out.println(" | | ");
System.out.println(" " + zero + " | " + one + " | " + two + " ");
System.out.println(" | | ");
System.out.println(" -------------------------------");
System.out.println(" | | ");
System.out.println(" " + three + " | " + four + " | " + five + " ");
System.out.println(" | | ");
System.out.println(" -------------------------------");
System.out.println(" | | ");
System.out.println(" " + six + " | " + seven + " | " + eight + " ");
System.out.println(" | | ");
}
Working...
The above program would in the first case render the block that you've shown first. Then you can get the input from user and update the variables, something like this,
MyClass.one = 'X';
You will be using a switch statement or an if else condition to check what was the input. Then for every key input you will also trigger the render function.
render();
Now when the function would be called again, it would render the new input for that previous number (which would now be "x").