What does Scanner = new scanner (System.in) mean?

Scanner input = new Scanner(System.in);

Could you give me a detailed explanation of what the above code does step by step? I really don’t understand how this works and how he contacts me later, having the opportunity to make this expression:

int i = input.nextInt()
+4
source share
4 answers

Well, let's take a closer look with a simplified class explanation Scanner.

This is a standard Oracle class that you can use by calling import java.util.Scanner.

So, let's make a basic class example:

class Scanner{
   InputStream source;

   Scanner(InputStream src){
       this.source = src;
   }

   int nextInt(){
       int nextInteger;
       //Scans the next token of the input as an int from the source.
       return nextInteger;
   }
}

, Scanner input = new Scanner(System.in);, Scanner ( "" ), input. ( ) System.in. , .

, input.nextInt();, ( documented). , , , , , , :

int i = input.nextInt();
+2

Scanner input = new Scanner(System.in); Scanner, , . .

, , integers, strings .

+2
Scanner input = new Scanner(System.in);

Scanner ( , , )

int i = input.nextInt()

nextInt , , .

0

s = (System.in);

Scanner, java.util.scanner . .

System.in is passed as a parameter in the scanner class, it will indicate the input of the java compiler system through the console (keyboard).

0
source

All Articles