How do I write the calc result on the same line as the scanner in JAVA?

Viewed 29

I would like to write the result of any calculation on the same line where the user enters the input (scanner).

For a better understanding of my question - Code example:

Scanner scanner = new Scanner(System.in);

int num1 = scanner.nextInt(); // num = 1

String op = scanner.next();     // operator = +  // I know this line is being ignored.
                                                 // It's just to keep a line of reasoning.
int num2 = scanner.nextInt(); // num = 2

System.out.print(" = " + num1+num2);

Output from IDE:

1 + 2
 = 3

Desired output:

1 + 2 = 3
0 Answers
Related