Tuesday 14 May 2019

What is scanner class in Java? tccicomputercoaching.com

Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double etc. and strings. Using Scanner class we can enter the data at run time.

The Java Scanner class breaks the input into tokens using a delimiter that is whitespace by default. It provides many methods to read and parse various primitive values. Java Scanner class is widely used to parse text for string and primitive types using a regular expression.



import java.util.Scanner;

public class inputdata
{
public static void main(String[] args)
{
//
Scanner input = new Scanner(System.in);
System.out.println("Enter the Name: ");
// String input
String name = input.nextLine();
System.out.println("Name: is "+name);
}
}

Output:

Enter the Name: mili

Name is mili

To learn more in detail about Java at TCCI

Call us @ 9825618292

Visit us @ www.tccicomputercoaching.com

No comments:

Post a Comment