Use the object generic model and ArraysList to enter and display the student information. The arrayslist student
Question: Enter and save the student information. When the student number is 0, the student information is displayed.
// Student Class
Public class Student {
Public int id;
Public String name;
Public int age;
Public Student (){
Super ();
}
Public Student (int id, String name, int age ){
Super ();
This. id = id;
This. name = name;
This. age = age;
}
// Text
Public class Text {
Public static void main (String [] args ){
System. out. println ("***** enter the student information. When the student number is 0, the end is *****");
Wrote input = new partition (System. in );
ArrayList <Student> arraylist = new ArrayList <Student> ();
// Enter Student Information
While (true ){
Student student = new Student ();
System. out. print ("Enter the student ID :");
Student. id = input. nextInt ();
If (student. id = 0 ){
System. out. println ("End entry! ");
Break;
} Else {
System. out. print ("Enter the Student name :");
Student. name = input. next ();
System. out. print ("Enter the student age :");
Student. age = input. nextInt ();
Arraylist. add (student );
}
}
// Output Student Information
System. out. println ("Student Information :");
System. out. println ("student ID \ t name \ t age ");
Iterator <Student> iterator = arraylist. iterator ();
While (iterator. hasNext ()){
Student a = iterator. next ();
System. out. println (a. id + "\ t" + a. name + "\ t" + a. age );
}
}
Running result: