+ 1
can anybody explain me this syntax scanner MyVar = New scanner (system.in);
5 Answers
+ 2
Scanner: the class of the object
MyVar: the name of the object
=: assignment operator
New Scanner(system.in): create a new object of type Scanner that will read from system.in (the input stream).
+ 2
the above statement is basically used to create a scanner object in order to cut short the tiresome process of printing new Scanner statement when the program requires multiple inputs
For example,
1. using scanner object :
Scanner myVar = new Scanner( System.in );
int a = myVar.nextInt();
int b = myVar.nextInt();
double c = myVar.nextDouble();
2. without scanner object :
int a = new Scanner(System.in).nextInt();
int b = new Scanner(System.in).nextInt();
double c = new Scanner(System.in).nextDouble();
As u can see it saves a great deal of time and energy. All this information may not be what u asked for but i ve tried to explain the basic use of this statement.
As for the meaning of the statement. It is exactly what Zen has given.
Hope u find this helpful !!! Happy coding !!
+ 1
used to get input from user that's it!!
0
thank you zen
0
thanks a lot