Develop a program to create a class Student with
data members student_name, roll_no&
branch. Initialize and display values of data members.
Program:
import java.lang.*;
import java.io.*;
class Student
{
String name;
int roll_no;
String branch;
void getdata() throws
IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.println
("Enter Name of Student");
name =
br.readLine();
System.out.println
("Enter Roll No. of Student");
roll_no =
Integer.parseInt(br.readLine());
System.out.println
("Enter branch name");
branch =
br.readLine();
}
void show() {
System.out.println
("Roll No. = "+roll_no);
System.out.println
("Name = "+name);
System.out.println
("Enter branch name = "+branch);
}
}
public class StudentDemo {
public static void
main(String[] args) throws IOException {
Student s=new
Student();
s.getdata();
s.show();
}
}
Output:
No comments:
Post a Comment