Some of the scanner class methods

posted Jan 20, 2014, 12:32 AM by iman baqir   [ updated Jan 20, 2014, 12:32 AM by Karwan Jacksi ]

Method                          Example and Description

nextByte                        Example Usage:

byte x;

Scanner keyboard • new Scanner(System.in);

System.out.print("Enter a byte value: ");

x = keyboard.nextBytef();

Description: Returns input as a byte.

 

 

nextDoubie                    Example Usage:

double number;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a double value: " );

number = keyboard.nextDoubie();

Description: Returns input as a double.

 

 

nextFloat                       Example Usage:

float number;

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a float value: ");

number = keyboard.nextFloa();

Description: Returns input as a float .

 

 

Nextlnt                           Example Usage:

int number;

Scanner keyboard = new Scanner(System.in);

System.out.print(“Enter an integer value: “);

number = keyboard.nextlnt();

Description: Returns input as an int;

 

 

ncxtLinc                         Example Usage:

String name;

Scanner keyboard = new Scanner(System.in);

System.out,print(“Enter your name: “);

name = keyboard.ncxtLinc();

Description: Returns input as a string.

 

                                     

nextLong                        Example Usage:

long number;

Scanner keyboard = new Scanner(System.in);

System.out.print(“Enter a long value: “);

number = keyboard.nextLongf();

Description: Returns input as a long.

 

 

nextShort                       Example Usage:

short number;

Scanner keyboard = new Scanner(Systcm.in);

System.out.print(“Enter a short value: “);

number = keyboard.nextShort();

Description: Returns input as a short.

 

Comments