Hey please can anybody tell me whats wrong in this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hey please can anybody tell me whats wrong in this code

import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.print("ENTER YOUR FIRST NUMBER? - "); int num = sc.nextInt(); Scanner sca=new Scanner (System.in); int numb=sca.nextInt(); int add=num+numb; System.out.println(add); } }

26th May 2018, 2:57 AM
praveen
praveen - avatar
4 Answers
+ 6
Don't use multiple scanners. Use the same scanner to get input. Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int numb = sc.nextInt();
26th May 2018, 3:13 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
One scanner works for any number of input, as I have demonstrated.
26th May 2018, 3:29 AM
Hatsy Rei
Hatsy Rei - avatar
0
and what if i want two inputd
26th May 2018, 3:18 AM
praveen
praveen - avatar
0
please reply vro
26th May 2018, 3:18 AM
praveen
praveen - avatar