If I understand your question, then this
System.out.println(tot);
System.out.print(a + b + c);
should be
System.out.print(tot);
System.out.println(a + b + c);
When I make the change above, I get output like you seem to be asking for –
Number 1: 1
Number 2: 3
Number 3: 5
Total: 9
Another option would be to use printf
and something like
System.out.printf("%s %d%n", tot, a + b + c);
1
solved String Var with int var [closed]