[SOLVED] Array Mode Problem
Hi there.
I'm stuck on a bit of programming, and not through lack of trying.
I have an array of students' marks.
I need to find the modes.
Code:
public static void mode(int classMarks[])
{
int[] marksArray = new int[21]; //creates an array that has an entry for each possible mark
int[] marks = classMarks;
System.out.println("The mode most frequently recurring mark(s):");
for(int i = 0; i < 21; i++)
{
for(int j = 0; j < NUMBER_OF_STUDENTS; j++)
{
if(marksArray[i] == marks[j]) //condition:if the mark value appears in the student marks array
{
marksArray[i]+= 1; //every mark adds 1 to the corresponding value in the array
}
}
}
}
I just can't figure out how to have multiple modes found and return the values, partially because I'm not sure how many modes to expect since it is based on user input.
Any tips or hints to help me go in the right direction?