# Sorting number and String arrays in descending order and alphabetical

Page 1 of 1

## 1 Replies - 6583 Views - Last Post: 28 January 2011 - 07:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=212681&amp;s=605a3075134e2fae184a99a6ecb97e4f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sampsoni

Reputation: 0
• Posts: 56
• Joined: 25-October 09

# Sorting number and String arrays in descending order and alphabetical

Posted 28 January 2011 - 07:18 PM

I'm trying to complete my first homework assignment in Programming Principles #2 and I'm trying to make a class that will sort two different arrays. A double value array will be arranged in descending order, while a String value array will be arranged in alphabetical order. My professor gave me a hint, and I need some help for the code I'm about to post because I think I made a few errors. He said I could copy a bit of code from my book and then modify it a bit to make it work. I just have to reverse it from ascending to descending. Here's my code:

```public class GradeSort {
private String[] names;
private int[] scores;

public void sort(String[] theNames, int[] theScores){

names = theNames;
scores = theScores;

for(int i = 1; i < theScores.length; i++){
double number = theScores[i];
int numberindex = i;
for(int j = 0; j < theScores.length + 1; j++){
if (number > theScores[j]){
number = theScores[j];
numberindex = j;
}
}
if(numberindex != i){
theScores[numberindex] = theScores[i];
theScores[i] = (int)number;
}
}
}
}

```

My IDE, Eclipse, is also giving me a few incompatible data types and operators. Can you help me correct those?

Is This A Good Question/Topic? 0

## Replies To: Sorting number and String arrays in descending order and alphabetical

### #2 Dogstopper

Reputation: 2965
• Posts: 11,222
• Joined: 15-July 08

## Re: Sorting number and String arrays in descending order and alphabetical

Posted 28 January 2011 - 07:23 PM

So loop it from array.length-1 to 0, i--, each time and instead of shifting backwards, shift forwards.