Right now, the program is determining and outputting the medal standings in descending order, however, I would like to determine and output the medal standings in ascending order. I'm not sure how to change my program in order to accomplish this task, if anyone is able to guide me onto the right path, that would be much appreciated.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class OlympicMedals2D {
public static void main (String [] args) {
// Initializing variables.
String country[] = {"Norway", "Germany", "Canada", "United States", "Netherlands", "South Korea", "Russia", "Switzerland", "France", "Sweden", "Austria", "Japan", "Italy", "China", "Czech Republic", "Finland", "Britain", "Belarus", "Slovakia", "Australia", "Poland", "Slovenia", "Spain", "New Zealand", "Hungary", "Ukraine", "Belgium", "Kazakhstan", "Latvia", "Liechtenstein"};
String countryMostTotalMedals = null;
String countryMostGoldMedals = null;
String countryMostSilverMedals = null;
String countryMostBronzeMedals = null;
int medals[][] = {{14, 14, 11}, {14, 10, 7}, {11, 8, 10}, {9, 8, 6}, {8, 6, 6}, {5, 8, 4}, {2, 6, 9}, {5, 6, 4}, {5, 4, 1}, {7, 6, 1}, {5, 3, 6}, {4, 5, 4}, {3, 2, 5}, {1, 6, 2}, {2, 2, 3}, {1, 1, 4}, {1, 0, 4}, {2, 1, 0}, {1, 2, 0}, {0, 2, 1}, {1, 0, 1}, {0, 1, 1}, {0, 0, 2}, {0, 0, 2}, {1, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 1}, {0, 0, 1}};
int totalMedals[] = new int [medals.length];
int mostTotalMedals = 0;
int greatestTotalMedals = 0;
int mostGoldMedals = 0;
int mostSilverMedals = 0;
int mostBronzeMedals = 0;
int medalCounter = 0;
int row;
int column;
// Determining country with highest total, gold, silver, and bronze medal count.
for (row = 0; row < medals.length; row += 1) {
for (column = 0; column < medals[row].length; column += 1) {
totalMedals[row] = totalMedals[row] + medals[row][column];
if (mostGoldMedals < medals[row][0]) {
mostGoldMedals = medals[row][0];
countryMostGoldMedals = country[row];
}
if (mostSilverMedals < medals[row][1]) {
mostSilverMedals = medals[row][1];
countryMostSilverMedals = country[row];
}
if (mostBronzeMedals < medals[row][2]) {
mostBronzeMedals = medals[row][2];
countryMostBronzeMedals = country[row];
}
}
if (mostTotalMedals < totalMedals[row]) {
mostTotalMedals = totalMedals[row];
countryMostTotalMedals = country[row];
}
}
// Outputting country with highest total, gold, silver, and bronze medal count.
System.out.println("The country with the most total medals is " + countryMostTotalMedals + " with " + mostTotalMedals + ".");
System.out.println("The country with the most gold medals is " + countryMostGoldMedals + " with " + mostGoldMedals + ".");
System.out.println("The country with the most silver medals is " + countryMostSilverMedals + " with " + mostSilverMedals + ".");
System.out.println("The country with the most bronze medals is " + countryMostBronzeMedals + " with " + mostBronzeMedals + ".");
System.out.println("\nMedal Standings");
// Determining medal standings in descending order (I would like to be able to determine the medal standings in ascending order).
for (row = 0; row < medals.length; row += 1) {
for (column = 0; column < medals.length; column += 1) {
if (totalMedals[column] > greatestTotalMedals) {
greatestTotalMedals = totalMedals[column];
medalCounter = column;
}
}
// Outputting medal standings in descending order (I would like to be able to output the medal standings in ascending order).
System.out.println(country[medalCounter] + "\t" + totalMedals[medalCounter]);
totalMedals[medalCounter] = 0;
medalCounter = 0;
greatestTotalMedals = 0;
medalCounter = 0;
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------