Computer Applications
Explain data input technique in a program using the Scanner class.
Input in Java
47 Likes
Answer
The data entered by the user through the keyboard is provided to our Java program with the help of standard input stream that is specified as System.in in the program. We connect our Scanner class to this stream while creating its object. The input received by Scanner class is broken into tokens using a delimiter pattern. The default delimiter is whitespace. Scanner class provides various next methods to read these tokens from the stream. The different next methods provided by Scanner class are next(), nextShort(), nextInt(), nextLong(), nextFloat(), nextDouble(), nextLine(), next().charAt(0).
Answered By
29 Likes
Related Questions
Suppose you want to use the class MyClass of the package MyPackage.UtilityLibrary in a program you are writing. What do you need to do to make the following?
i. class MyClass available to your program
ii. all the classes of the package available to your program
What are errors in a program?
What are delimiters? Which is the default delimiter used in the Scanner class?
Explain the following terms, giving an example of each.
i. Syntax error
ii. Runtime error
iii. Logical error