Any other way of initializing Scanner class | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

Any other way of initializing Scanner class

Traditionally we initialise scanner class like this: Scanner sc=new Scanner(System.in); Int a=sc.netInt(); I read in a book that it can be initialised by some other way. I have forgotten it now but it was something like this: int a=nextInt().new Scanner(System.in); I tried it but it gave me an error. Does somebody knows how to do it??

27th Sep 2020, 2:53 PM
Divyansh
Divyansh - avatar
2 Antworten
+ 4
It could be int a = new Scanner(System.in).nextInt()
27th Sep 2020, 2:56 PM
Raj Chhatrala
Raj Chhatrala - avatar
27th Sep 2020, 3:44 PM
Divyansh
Divyansh - avatar