0

Is this the only way to seperate 2 inputs and add them together? I would of liked to do this in one print but a string brakes it

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x,y; x = in.nextInt(); y = in.nextInt(); System.out.println ("Input 1 = " + x + "\n" +"Input 2 = " + y + "\n\n" + "Input1 + Input2 ="); System.out.println(x + y); } }

24th Jun 2017, 5:46 PM
Uni Verse
Uni Verse - avatar
2 odpowiedzi
+ 4
Use brackets. ...println("Input1 + Input2 = " + (a + b));
24th Jun 2017, 5:57 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
@faith spot on thanks
24th Jun 2017, 8:55 PM
Uni Verse
Uni Verse - avatar