32 - Input From Keyboard In Java Using Scanner Class - By EZEON

Published: 19 September 2017
on channel: Vikram Thakur
961
14

Javadoc of java.util.Scanner :
A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods (nextInt(), nextByte(), nextFloat(), next(), nextLine()).

Sample Code:

Scanner s = new Scanner(System.in);
System.out.println("Enter an int value : ");
int i = s.nextInt();
System.out.println("Value of i = " + i);

System.out.println("Enter a float value : ");
float f = s.nextFloat();
System.out.println("Value of f = " + f);

System.out.println("Enter a String value : ");
String str = s.next();
System.out.println("Value of str = " + str);

s.nextLine();

System.out.println("Enter a line : ");
String line = s.nextLine();
System.out.println("Input Line = " + line);

SCANNER CAN BE CREATED USING DIFFERENT SOURCE:
Scanner(File source)
Scanner(InputStream source) : its used in our example
Scanner(Path source)
Scanner(ReadableByteChannel source)
Scanner(String source)


On this page of the site you can watch the video online 32 - Input From Keyboard In Java Using Scanner Class - By EZEON with a duration of hours minute second in good quality, which was uploaded by the user Vikram Thakur 19 September 2017, share the link with friends and acquaintances, this video has already been watched 961 times on youtube and it was liked by 14 viewers. Enjoy your viewing!