+ 1

what does Scanner(System.in) mean?

I know to create an instance of the scanner class we used scanner myvar= new ; scanner(system.in); but what is the use of the last line?

25th May 2019, 5:20 PM
Rivita Chowdhury
Rivita Chowdhury - avatar
4 Antworten
+ 17
Scanner is class in java which is used to get input from user.
25th May 2019, 9:07 PM
Priyanka♥️
+ 4
Scanner is a pre defined class in java available on java.util package....it is coded in such a way to get an input from user.... Scanner scan = new Scanner(System.in); the above line creates an instance for object scan of class Scanner....you can use scan object for getting user input....
28th May 2019, 5:45 AM
Thanigai Velan
Thanigai Velan - avatar
+ 2
Here you have some errors. Scanner myvar = new Scanner(System.in); This is the correct line Here you are creating an instance variable of Scanner class. By System.in you are saying that hey! I will take input from the console! Hope you have got the point!
25th May 2019, 5:36 PM
ART
ART - avatar
+ 2
System.in is variable with definition about what is standard input stream. usualy it is console user keyboard input. Scanner is class for read this input stream. import java.util.Scanner; class Example { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Input numbers"); int n = 1, sum=0; while( sc.hasNextInt() ) { n = sc.nextInt(); //read int number from input System.out.printf( "%d + %d = %d\n", sum, n, sum+=n); } } }
25th May 2019, 6:36 PM
zemiak