Computer Science, asked by satyamguptaa, 1 year ago

methods of scanner class ​

Answers

Answered by gautham234
5

Answer:

Explanation:

Scanner class

It is used to create an object which is used to read data from input stream (keyboard).

Scanner class is defined in java.util package. So, we need to import this packet first before using the methods of Scanner class.

Objects are references variables in Java.

Constructor

Scanner (object)

Method of Constructor

Scanner object_name  = new Scanner(input_stream_reference);

Example:

Scanner input = new Scanner (System.in);

Here, System.in is the reference of input (keyboard).

Methods of Scanner class

Here, we are discussing some of the important methods of Scanner class, which are used to design a Java program with user input. The methods are:

1) int nextInt()

It is used to read an integer value from the keyboard.

2) int nextFloat()

It is used to read a float value from the keyboard.

3) long nextLong()

It is used to read a long value from the keyboard.

4) String next()

It is used to read string value from the keyboard.

Answered by DNA7777
4

Answer:

1) int nextInt

2)int nextFloat

3)long nextLong

4)String next

Similar questions