# Java Sorting Students in Decreasing Order by Score

Discussion in 'Java' started by MoonBeam080680, Apr 17, 2011.

1. ### MoonBeam080680New Member

Joined:
Apr 17, 2011
Messages:
1
0
Trophy Points:
0
I am trying to get this program to sort the students in decreasing order by their score. I keep getting an error message when I try to use SelectionSort. This is the error I receive.
C:\Users\Jen>javac Sort.java
Sort.java:36: selectionSort(int[]) in Sort cannot be applied to (int)
int sortOutput = selectionSort(scores);
^
1 error

Here is the code I am using. Any help would be greatly appreciated.

Code:
```import java.util.*;
public class Sort {
public static void main(String[] args){
//Create Scanner
Scanner input = new Scanner(System.in);
//Get the number of students
System.out.print("Please enter the number of students: ");
int numberOfStudents;
String temp = input.nextLine();
numberOfStudents = Integer.parseInt(temp);
//Create Array
int[] scores = new int[numberOfStudents];
String [] names = new String[numberOfStudents];
Scanner input2 = new Scanner(System.in);
//Loops asking user to enter data
for (int i = 0; i < names.length; i ++){
names[i] = input.nextLine();
System.out.print("Please enter a score for the name: ");
scores[i] = input2.nextInt();
}
System.out.println("Students Highest to Lowest");
for (int i = 0; i < names.length; i++){
String output = " ";
output = names[i] + " score is " + scores[i] + "\n";

System.out.println(output);
int sortOutput = selectionSort(scores[i]);
}

}
public static void selectionSort(int [] scores){
for (int i = scores.length - 1; i >= 1; i--){
//Find the max in the scores array
int max = scores;
int maxIndex = 0;
for (int j = 1; j <= i; j++){
if(max < scores[j]){
max = scores[j];
maxIndex = j;
}
}
// Swap scores as necessary
if (maxIndex != i){
scores[maxIndex] = scores[i];
scores[i] = max;
}
}
}
}```

2. ### ManzZupNew Member

Joined:
May 9, 2009
Messages:
278
43
Trophy Points:
0
Occupation:
Production Manager:Software @ ZONTEK
Location:
Sri Lanka
why are you making the selection sort?
the arrays of java contains the sort method

3. ### szilla211New Member

Joined:
Jul 5, 2012
Messages:
1
lemme know if this helps
{"ft_lang_label":"__label__en","ft_lang_prob":0.5998937,"math_prob":0.86501473,"size":1706,"snap":"2020-45-2020-50","text_gpt3_token_len":430,"char_repetition_ratio":0.13043478,"word_repetition_ratio":0.030303031,"special_character_ratio":0.3059789,"punctuation_ratio":0.20535715,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98045504,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-25T22:12:52Z\",\"WARC-Record-ID\":\"<urn:uuid:f4eb7c58-03b2-4daa-af3d-86fb79689be8>\",\"Content-Length\":\"45569\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:29725d6f-f954-4511-acc7-34a94c405dd7>\",\"WARC-Concurrent-To\":\"<urn:uuid:8eda5e50-01a2-445e-b2f4-f23adf8a358b>\",\"WARC-IP-Address\":\"173.230.137.46\",\"WARC-Target-URI\":\"https://www.go4expert.com/forums/java-sorting-students-decreasing-score-t25548/\",\"WARC-Payload-Digest\":\"sha1:7CQGVM3STU4EUNFPIK3J5SVIPSMW3WMB\",\"WARC-Block-Digest\":\"sha1:RUWHV6NSMCXC57NKRD4PZK2WKEX4N4ZM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141184870.26_warc_CC-MAIN-20201125213038-20201126003038-00609.warc.gz\"}"}