Experiment 2
Experiment 2
Experiment 2
Aim: Programs on accepting input through keyboard (LO1)
Theory
Scanner class
The Scanner class in Java, part of the java.util package, is a versatile and easy-to-use
class
designed for parsing primitive types and strings using regular expressions.
Introduced in Java 5, it is widely used for reading input from various sources,
such as the console, files, and strings.
BufferedReader class
The BufferedReader class, part of the java.io package, is designed to efficiently
read text from character input streams, such as files or network connections. It
buffers the input to provide efficient reading of characters, arrays, and lines.
Scanner BufferedReader
Can read from InputStream, File, Typically used with character input
Path, and String. streams like FileReader or
InputStreamReader.
1. Program on taking an input from a user using BufferedReader and check whether it
is a 2- digit number or not.
Code:
Output:
2. WAP on taking an input character Grade from Scanner object and printing its
corresponding percentage as below:
Percentage Grade 0-60 F
61-70 D
71-80 C
81-90 B
91-100 A
(rest grades can be printed as Out of Range)
Anish Dharnidhar AI & DS Batch S23 Roll no : 129
Code:
Output:
Anish Dharnidhar AI & DS Batch S23 Roll no : 129
3. WAP to read and display details of Student : Name, Age, Address, Branch, Batch,
PhoneNumber using Scanner class.
Code:
Anish Dharnidhar AI & DS Batch S23 Roll no : 129
Output: