+ 1

user input 2 numbers , add and print here in sl ?? java

is there some problem with my system or more than one user input in java here at SL not allowed??

2nd Sep 2017, 6:33 PM
vivek sahal
vivek sahal - avatar
3 Answers
+ 7
import java.util.Scanner; public class Program { public static void main(String[] args) { int i,j; Scanner inp=new Scanner(System.in); i=inp.nextInt(); j=inp.nextInt(); System.out.println(i+j); } } Input should be in separate lines : 1 2 output:3
2nd Sep 2017, 6:55 PM
P R
P R - avatar
+ 3
Multiple inputs can be collected by separating them with a new line. Example (Code Playground): 1 2
2nd Sep 2017, 6:37 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
ok i got it that in same input box we can input more than 1 value pressing enter each time but how user will know about number of inputs?? public class Program { public static void main(String[] args) { public class Program { public static void main(String[] args) { int i,j; System.out.println("Enter two numbers to add:"); //this msg gets displayed with result Scanner inp=new Scanner(System.in); i=inp.nextInt(); j=inp.nextInt(); System.out.println(i+j); } } } } //Input should be in separate lines : 1 2 output:3
2nd Sep 2017, 7:24 PM
vivek sahal
vivek sahal - avatar