+ 2

Scanner

Is it possible to use more than one scanner in a code?

28th Jan 2017, 2:58 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
11 Respostas
+ 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
28th Jan 2017, 5:29 PM
Kommoju Sunil Kumar
Kommoju Sunil Kumar - avatar
+ 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
29th Jan 2017, 9:17 AM
Kawaii
Kawaii - avatar
+ 1
yes
28th Jan 2017, 3:06 AM
Kawaii
Kawaii - avatar
+ 1
Can you please explain how? @N3tW0rK
28th Jan 2017, 3:07 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
Scanner var1 = new Scanner(System.in); Scanner var2 = new Scanner(System.in);
28th Jan 2017, 3:32 AM
Kawaii
Kawaii - avatar
+ 1
Thank you Mr. Sunil for your thought-provoking program but can we use"Scanner" twice as N3tw0rk replied already?
28th Jan 2017, 6:43 PM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
@N3tw0rk, I tried that but it is not working. Can you please check?
29th Jan 2017, 8:52 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 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?
29th Jan 2017, 9:06 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
@N3tw0rk, did u compile that code of yours?
29th Jan 2017, 9:31 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 1
Because I am getting runtime errors
29th Jan 2017, 9:31 AM
tharun surya dwivedula
tharun surya dwivedula - avatar
+ 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
29th Jan 2017, 1:01 PM
Kawaii
Kawaii - avatar