Storing the object in an array, and then iterating through the array, plus the operation of some arrays, is simple, purely recorded
Import Java.util.Scanner;
public class Studentmanagertwice {
public static void Main (string[] args) {
Student1 stu = new Student1 ("AAA", 12,1201);
Student1 STU2 = new Student1 ("BBB", 34,1202);
Student1 stu3 = new Student1 ("CCC", 14,1203);
Student1 stu4 = new Student1 ("ddd", 16,1204);
Student1 stu5 = new Student1 ("Eee", 11,1204);
student1[] Stus = new STUDENT1[5];
Stus[0] = stu;
STUS[1] = STU2;
STUS[2] = STU3;
STUS[3] = Stu4;
STUS[4] = Stu5;
String answer = "";
Scanner input = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("-----welcomecome to the Students manager System-----");
do {
System.out.println ("1.look all 2.query stunum");
System.out.println ("3.exit 4.without");
int choice = Input.nextint ();
Switch (choice) {
Case 1:
for (int i = 0; i < stus.length; i++) {
System.out.println (Stus[i]);
}
Break
Case 2:
SYSTEM.OUT.PRINTLN ("Please input a stunum:");
int num = Input.nextint ();
for (int i = 0; i < stus.length; i++) {
Student1 s = stus[i];
if (num = = S.getstunum ()) {
System.out.println (s);
Break It ended the cycle early with a break and improved efficiency, but
}
}
Break
Case 3:
System.exit (0);
Break
Default
Break
}
System.out.println ("Continue? <y/n> ");
Answer = Input.next ();
} while (Answer.equals ("Y"));
}
}
Class student1{
private String name;
private int age;
private int stunum;
Public Student1 () {
Super ();
TODO auto-generated Constructor stub
}
Public Student1 (String name, int age, int stunum) {
Super ();
THIS.name = name;
This.age = age;
This.stunum = Stunum;
}
@Override
Public String toString () {
Return "Studetn [name=" + name + ", age=" + Age + ", stunum=" + stunum
+ "]";
}
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
public int Getstunum () {
return stunum;
}
public void Setstunum (int stunum) {
This.stunum = Stunum;
}
}
Java using arrays to implement a simple student management system