+ 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); } }
4 Réponses
+ 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();
+ 4
One scanner works for any number of input, as I have demonstrated.
0
and what if i want two inputd
0
please reply vro