0% found this document useful (0 votes)
17 views3 pages

Scanner Class by Kunal Sir Official

Notes

Uploaded by

Gopal Nanne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Scanner Class by Kunal Sir Official

Notes

Uploaded by

Gopal Nanne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

by Kunal Sir

SCANNER IN JAVA: -

1. Java Scanner class is part of the java.util package.

2. It was introduced in java 1.5 version release.

3. The Scanner class is used to get user input, from the


keyboard at the runtime.

4. In order to use the Scanner class, you can create an object


of the class and use any of the Scanner class methods.

5. The java Scanner class extends Object class and


implements Iterator and Closeable interfaces.

OBJECT CREATION OF SCANNER CLASS: -

Scanner sc = new Scanner(System.in);

where –
Scanner  Inbuilt Class
sc  Reference variable / object
new  Keyword (responsible for object creation)
System  Inbuilt Class
.in  Input

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir

METHODS OF SCANNER CLASS IN JAVA: -


There are some methods available inside the scanner class in java which
is given below –

S.NO. METHOD NAME DISCRIPTION

1. nextInt( ) Used for reading int value

2. nextFloat( ) Used for reading float value

3. nextDouble( ) Used for reading double value

4. nextByte( ) Used for reading Byte value

5. nextBoolean( ) Used for reading Boolean value

6. nextLong( ) Used for reading long value

7. nextShort( ) Used for reading short value

8. nextLine( ) Used for reading String value

9. next( ).charAt(0) Used for reading char value

10. next( ) Used for reading String value

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir

BASIC PROGRAM BY USING SCANNER IN JAVA: -

import java.util.Scanner;

public class Calculation


{
Scanner sc = new Scanner(System.in);

public void addition( )


{
System.out.println(“Enter the value of a : ”);
int a = sc.nextInt();

System.out.println(“Enter the value of b : ”);


int b = sc.nextInt();

int c = a + b;
System.out.println(“Addition = ”+c);
}

public class Test


{
public static void main(String args[])
{
System.out.println(“Main Method Start”);

Calculation c = new Calculation();


c.addition( );

System.out.println(“Main Method End”);


}
}

Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204

You might also like