+ 1
How to use scanner function multiple times in java
Plz tell
4 Answers
+ 2
If you mean in Code Playground, then use just 1 Scanner object to read all the necessary inputs.
Please put Java in your thread tags above â
+ 4
Thnx all of u
+ 2
Scanner is a class. In most cases instantiating it once is more than enough because you only use the reference to accept inputs and the actual object doesn't have anything to do with it.
+ 2
Hardik Mishra
// import it
import java.util.Scanner;
// make an object
Scanner sc =new Scanner(System.in) ;
// use it
int n = sc.nextInt() ;
String str = sc.next() ;
....... etc.....
// close it if you wish
sc.close() ;