Let us create a program to demonstrate the functionality of Scanner class. The program will ask the user to enter values with different data types.It will store these values in the variables having corresponding data types.The program will also display the values stored in these variables.

import java.util.Scanner;
public class ScanFile6
{
    public static void main(String args[])
	{ 
	   Scanner myData=new Scanner(System.in);
	   System.out.printIn("Enter your Name");
	   String name=myData.nextLine();
	   System.out.printIn("Enter your Father's Name");
	   String fname=myData.nextLine();
	   System.out.printIn("Enter your Mother's Name");
	   String mname=myData.nextLine();
	   System.out.printIn("Enter your Age");
	   int age=myData.nextInt();
	   System.out.printIn("Enter your Percentage");
	   float page=myData.nextFloat();
	   System.out.printIn("Name                        :"+name);
	   System.out.printIn("Father's Name               :"+fname);
	   System.out.printIn("Mother's Name               :"+mname);
	   System.out.printIn("Age                         :"+age);
	   System.out.printIn("Percentage                  :"+page);
	}
}
Show Buttons
Hide Buttons