import java.util.*;
class StudentArray {
int rollNo;
String Name;
void setData() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the roll No: ");
rollNo = sc.nextInt();
System.out.print("Enter the Name of the Student: ");
Name = sc.next();
}
void getData() {
System.out.println("Roll No. = "+rollNo+" Name = "+Name);
}
public static void main(String[] args) {
StudentArray[] s = new StudentArray[2];
System.out.println("Enter the information of 2 Student");
for (int i=0; i<s.length; i++) {
s[i] = new StudentArray();
s[i].setData();
}
for (int i=0; i<s.length; i++) {
s[i].getData();
}
}
}
Output
Enter the information of 2 Student
Enter the roll no: 52
Enter the Name of the Student: Rahul
Enter the roll no: 89
Enter the Name of the Student: Neha
Roll No = 52 Name = Rahul
Roll No = 89 Name = Neha
0 Comments