After playing a lot around the code I found the following trick. I would request you to first look at the following code:
Code:
System.out.printf("%s \t \t %s\n", "Operation", "Result");
String format = "%-28s %-7d \n";
String operators = Integer.toString(num1) + "+" + Integer.toString(num2);
System.out.printf(format, operators, total);
The resulting input will be no doubt similar as per your requirement. Here what I did is made use of the following things:
- %s – which is for String value
- %d – representing decimal value
- \n – for newline
I converted the two numbers into string first combining them together into a string value called as Operators. Then I printed all of them together.
Bookmarks