lundi 22 juin 2015

my java program only preforms actions sequentially

I have the following code in my program:

public static void remove(int studentID)
    {
        for (int i = 0; i < students.length; i++)
        {
            if (roster.get(i).getStudentID()==studentID)
            {
                System.out.println("Student with Student ID of: " + studentID + " has been removed!");
                roster.remove(i);
                return;
            }
            else
            {
               System.out.println("Student with Student ID of: " + studentID + " could not be found! No action taken! ");
               return;
            }
        }
    }

Everything seems to compile fine, but when I do a roster.remove I can only sequentially delete a ID out of the array list. I have 5 listings in my array, and if I run the remove method from 1 to 5 it works. However if I start at a number say 2, my loop cannot find the ID and fails.

Being relatively new at Java, I know this may be a simple question, I just simply need help. banging my head against the keyboard has produced nothing of value for this problem.

Thank you very much for any help!

Aucun commentaire:

Enregistrer un commentaire