In: Computer Science
IN JAVA write a program that creates an array of strings with 8
people in it. Second, Assign a random rank between 1 to
8 to each of the players. The rankings do not change throughout the
tournament. Finally, Sort the players based on the rankings and
print the data (show rankings of players, in square brackets, at
every step after they are ranked).
USING JAVA COLLECTIONS IS NOT ALLOWED
public class PlayerSort { public static void main(String[] args) { String[] names = {"Ronaldo", "Messi", "Bale", "Neymar", "Isco", "Hazard", "Mbappe", "Sterling"}; int[] ranks = {1, 2, 5, 3, 8, 4, 6, 7}; // sorting here String tempName; int tempRank; for (int i = 0; i < names.length; i++) { for (int j = 0; j < names.length-1; j++) { if (ranks[j] > ranks[j+1]) { tempName = names[j]; names[j] = names[j+1]; names[j+1] = tempName; tempRank = ranks[j]; ranks[j] = ranks[j+1]; ranks[j+1] = tempRank; } } } // print players System.out.println("Players sorted by ranks are:"); for (int i = 0; i < names.length; i++) { System.out.println(ranks[i] + ". " + names[i]); } } }