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); } }
2 Réponses
+ 4
Use brackets.
...println("Input1 + Input2 = " + (a + b));
+ 2
@faith spot on thanks