0

What is wrong with this code?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner one = new Scanner(System.in); int a = one.nextInt(); //first number Scanner two = new Scanner(System.in); int b = two.nextInt(); //second number System.out.println (a+b); } }

22nd Jan 2017, 9:37 AM
Devansh Das
Devansh Das - avatar
6 Answers
+ 4
Why are you trying to create a whole new Scanner object to read in user input when you already have one?
22nd Jan 2017, 9:54 AM
Nina
Nina - avatar
+ 4
Vaibhav Tandon gave you a great solution. I checked your code in the code playground. The extra Scanner was the only thing causing an error.
22nd Jan 2017, 4:11 PM
Nina
Nina - avatar
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner one = new Scanner(System.in); int a = one.nextInt(); //first number int b = one.nextInt(); //second number System.out.println (a+b); } }
22nd Jan 2017, 2:17 PM
Vaibhav Tandon
Vaibhav Tandon - avatar
0
How else to do it?
22nd Jan 2017, 1:00 PM
Devansh Das
Devansh Das - avatar
0
Please tell me how to get 2 inputs from a single scanner
25th Jan 2017, 10:36 AM
Devansh Das
Devansh Das - avatar