Click here to watch in Youtube :https://www.youtube.com/watch?v=2eCPzJb5I6c&list=UUhwKlOVR041tngjerWxVccwClick the below Image to Enlarge |
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
|
Java Tutorial : Java IO (Scanner class) |
ScannerDemo.java import java.util.Scanner;
/*
* Java Scanner class which reads the int,
* string and double value as an input:
*/
public class ScannerDemo
{
public static void main(String[] args)
{
Scanner scanner = null;
try
{
scanner = new Scanner(System.in);
System.out.print("Enter your Id: ");
int rollno = scanner.nextInt();
System.out.print("Enter your Name: ");
String name = scanner.next();
System.out.print("Enter your Weight: ");
double weight = scanner.nextDouble();
System.out.println("Id:" + rollno + ", Name:" + name
+ ", Weight:" + weight);
}
finally
{
if (scanner != null)
{
scanner.close();
}
}
}
}
Output Enter your Id: 54
Enter your Name: peter
Enter your Weight: 67.89
Id:54, Name:peter, Weight:67.89
Refer: https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Scanner.html