Actual use of scanner in the code

what is scanner and why add this before the code ?
and its syntax explaination

Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double, etc. and strings. It is the easiest way to read input in a Java program, though not very efficient if you want an input method for scenarios where time is a constraint like in competitive programming.

After importing, we need to write the following statement in our program.

Scanner s = new Scanner (System.in);

Here by writing Scanner s, we are declaring s as an object of Scanner class. System.in within the round brackets tells Java that this will be System Input i.e. input will be given to the system.

If this solves your doubt please mark it as resolved :slight_smile: