Can there multiple scanners in one program? Or can they only be declared once | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can there multiple scanners in one program? Or can they only be declared once

11th Mar 2022, 6:21 PM
Kekusina
Kekusina - avatar
3 Answers
+ 1
There can be many. But they should wrap around different input streams.
11th Mar 2022, 6:51 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
11th Mar 2022, 6:55 PM
Jayakrishna 🇮🇳
0
Sololearn doesn't support two Scanners of System.in but this exsmple works import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc1 = new Scanner("a b c d"); Scanner sc2 = new Scanner("1 2 3 4"); System.out.println( sc1.next() ); System.out.println( sc2.next() ); System.out.println( sc1.next() ); System.out.println( sc2.next() ); } }
11th Mar 2022, 8:01 PM
zemiak