+ 2
Scanner
Is it possible to use more than one scanner in a code?
11 Réponses
+ 3
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
        String  scan1,scan2;
        Scanner s1= new Scanner(System.in);
        scan1= s1.nextLine();
        scan2= s1.nextLine();
        System.out.println("The first line using scanner is:: "+scan1);
        
        System.out.println("The second line using scanner is:: "+scan2);
        
        
    }
}
Try this once. i think it might be helpful
+ 2
import java.util.Scanner;
class program {
    public static void main(String[] args) {
        String var1, var2;
        Scanner scan1 = new Scanner(System.in);
        Scanner scan2 = new Scanner(System.in);
        var1 = scan1.nextline();
        var2 = scan2.nextline();
    }
}
u can use more than 1 scanner but its easier to use just one like sunil did before
+ 1
yes
+ 1
Can you please explain how? @N3tW0rK
+ 1
Scanner var1 = new Scanner(System.in);
Scanner var2 = new Scanner(System.in);
+ 1
Thank you Mr. Sunil for your thought-provoking program but can we use"Scanner" twice as N3tw0rk replied already?
+ 1
@N3tw0rk, I tried that but it is not working. Can you please check?
+ 1
@Sunil, Thank you. I tried your code. It's working and helpful. So, can we conclude that it is not possible to use Scanner twice in a program?
+ 1
@N3tw0rk, did u compile that code of yours?
+ 1
Because I am getting runtime errors
+ 1
yh i did on my pc but with int instead of string but I think that doesnt change anything if u r trying here maybe is a problem with their compiler



