Search code examples
line

Is it possible to accept user input between 2 outputs in the same line


What i want to do is that terminal displays the following:

mass = ___ Kg

Where the blank space denotes the area where the user can input a value. I doubt it may not possible within a terminal and couldn't find any reassuring documentation, but still thought it would be worth asking more experienced programmers


Solution

  • The only idea I have right now is to update the string with the number input and print it to the console after every input. Clean the console screen after each input. So that for example:

     sysout("mass = "+input+" kg";
     ==> mass = __ kg
     input += scanner.nextLine();
     sysout("mass = "+input+" kg")
     <clean console>
     ==> mass = 5_ kg ....