0% found this document useful (0 votes)
4 views2 pages

Java Program for User Input Handling

The document outlines an experiment to create a Java program that accepts user input for a Student class containing 'name', 'city', and 'age'. It demonstrates the use of Scanner and BufferedReader for input collection and displays the user details. The conclusion states that the program was successfully implemented.

Uploaded by

Shreya Ranjane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Java Program for User Input Handling

The document outlines an experiment to create a Java program that accepts user input for a Student class containing 'name', 'city', and 'age'. It demonstrates the use of Scanner and BufferedReader for input collection and displays the user details. The conclusion states that the program was successfully implemented.

Uploaded by

Shreya Ranjane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment No.

2
Roll No
Aim: Program on accepting input through keyboard

a. Write a program to create a class Student with data ‘name, city and age’ along with method printData
to display the data. Create the two objects s1 ,s2 to declare and access the values.

//Accept input using scanner and bufferreader classes


import [Link].*;
import [Link];
public class InputExample
{
public static void main(String[] args)throws IOException
{
//Using scanner for input
Scanner scanner=new Scanner([Link]);
[Link]("Enter your name:");
String name=[Link]();
[Link]("Enter your age:");
int age=[Link]();
//Using BufferedReader for input
BufferedReader reader=new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter your city:");
String city=[Link]();
//Displaying the inputs
[Link]("\n--User Details--");
[Link]("Name:"+name);
[Link]("Age:"+age);
[Link]("City:"+city);
}
}

Output:

Conclusion

Successfully implemented this program.

You might also like