0% found this document useful (0 votes)
1 views1 page

Scanner Method

Uploaded by

frrj2sc5rz
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)
1 views1 page

Scanner Method

Uploaded by

frrj2sc5rz
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

What is a Scanner?

The Scanner class allows us to read data from the user enter the console (keyboard).

It is widely used in Java to retrieve data from the user.

[Link]() Reads an entire line from the user (String)


[Link]() Reads an integer entered by the user int
[Link]() Reads a decimal number entered by the user double
[Link]() Reads a decimal number entered by the user float

Example code:

import [Link];

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

//Getting the name (String) from the user


[Link]("Enter the name: ");
String name = [Link]();

//Getting the age (int) from the user


[Link]("Enter the age: ");
int age = [Link]();

//Getting the salary (double) from the user


[Link]("Enter the salary: ");
double salary = [Link]();

//Printing the entered information to the screen


[Link]("Name: " + name);
[Link]("age: " + age);
[Link]("salary: " + salary);

}
}

You might also like