Java Language Provides many ways to input a data using keyboard on the run time of a program. Scanner class is one and the one of the best way for user input.
Scanner class found under the Java package java.util.Scanner. So we can import this package with the program and use this class.
import java.util.*;
// this package holds the all the feature /
function of Scanner class.
public class scan { public static void main (String args[]) { Scanner sc=new Scanner
(System.in); System.out.printil("Enter
Your City Name "); String Name=sc.nextLine(); System.out.println("City
Name is : " +Name); } } |
Output
Enter Your City
Name Bulandshahr City Name is : Bulandshahr
|
In the Above Program, First Line will import the java.util package which can be use to access the Scanner Class.
Scanner Class provide a number of method to input a Data from the user. By default System provide a String value which we convert as per the required Data or Value for Integer we use nextInt() and so on.
There is a List of Method of Scanner class on the basis of Data types...