我想以另一种方法将存储在一个 for 循环中的对象数组传递给第二个 for 循环以显示内容。例如:
public static Student[] add()
for(int i = 0; i < studentArray.length; i++)
{
System.out.print("Enter student name ");
studentName = EasyIn.getString();
System.out.print("Enter student Id ");
studentId = EasyIn.getString();
System.out.print("Enter mark ");
studentMark = EasyIn.getInt();
studentArray[i] = new Student(); //create object
tempObject = new Student(studentName,studentId,studentMark);
place = findPlace(studentArray,studentName, noOfElements);
noOfElements = addOne(studentArray, place, tempObject, noOfElements);
}
到这里
public static void displayAll()
{
Student[] anotherArray = add();
for(int i = 0; i < anotherArray.length ; i++)
{
System.out.print(anotherArray[i].toString());
}
}
在此处的菜单中调用它:
case '3': System.out.println("List All");
displayAll();
EasyIn.pause();
当我在菜单上按 3 时,它只是再次调用 add 方法,但是当我再次将值添加到数组中时,它会显示数组。我只想显示数组