0

I am making a CLI calculator and I am trying to add a clear button but cannot figure out how to clear all the user input and start the display from the beginning. I tried using the reset method and that didn't seem to do the trick.

        System.out.println("Enter any of the following:");
        System.out.println(" 1 2 3 4 5 6 7 8 9 ");
        System.out.println(" + - * / = ");
        System.out.println("Enter AC to reset ");

        double firstNum = input.nextDouble();
        input.nextLine();

        if (input.equals(clear)) {
            input.reset();

        }
        System.out.println("Display 1: " + firstNum);
        System.out.println("Display 2: " + firstNum);

        System.out.println("Operator: ");
        String operand = input.nextLine();

        System.out.println("Display 1: " + firstNum + " " + operand);
        System.out.println("Display 2: " + firstNum  );

        if (operand.equals("=")) {
            break;
        }

        System.out.println("Enter your next number: ");
        double secondNum = input.nextDouble();
        input.nextLine();

        calculate(firstNum, operand, secondNum);

        System.out.println("Display 1: " + firstNum + " " + operand + " " + secondNum );
        firstNum = answer;
        System.out.println("Display 2: " + answer);


         }
          System.out.println("Answer: " + answer);
        }

1 Answers1

0

I suppose it can't be done. I tried to solve the problem and this is a waste of time. If it helps, you can use special characters like "\b" to delete the previous character or "\r" to write from the beginning of the string. But when you press Enter, you can't change the previous line.

Vaiker
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 15 '22 at 11:30