I'm a new programmer to java, been using this website a lot to learn the ways. Today I've stumbled into another problem towards a program I'm doing for practice.
I have an array:
final int EXAMS = 5;
int[] scores = new int [EXAMS];
The values for this array are then asked from the user through a Scanner object:
for (int index = 0; index < EXAMS; index++)
{
System.out.println("Enter the score for " + (index+1) +":");
scores[index] = kb.nextInt();
if (scores[index] < 0){
System.out.println("The number you have entered is invalid.");
scores[index] = kb.nextInt();
}
}
I managed to make an ascending order sorting of the values "scores[]":
Arrays.sort(scores);
System.out.println("The sorted int array is:");
for (int number : scores)
{
System.out.println("Number = "+ number);
}
But I want the sorting to be in descending order. When I put the
Arrays.sort(scores, Collections.reverseOrder());
I get an error saying: "no suitable method found for sorting." Please help.