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); } }
6 Answers
+ 4
Why are you trying to create a whole new Scanner object to read in user input when you already have one?
+ 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.
+ 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);
}
}
0
How else to do it?
0
Please tell me how to get 2 inputs from a single scanner