I'm trying to write a program that prompt the user to enter the number of game players, the game players' names, their scores, and prints their scores' in decreasing order of their scores.
I need to do this using arrays for names and scores. Unfortunately this is all I have.
A sample output
Enter the number of players: n
Enter the name of the player: Ash
Enter the player's score: 1200
Enter the name of the player: Brock
Enter the player's score: 900
Enter the name of the player: Misty
Enter the player's score: 1300
Misty 1300.0
Ash 1200.0
Brock 900.0
import java. util.*;
public class HomeworkAssignment12 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of game players: ");
int numOfPlayers = input.nextInt();
String[] names = new String[numOfPlayers];
double[] scores = new double[numOfPlayers];
//Trying to store the names the user inputs into the names[] array
for ( int i = 0; i < names.length; i++) {
int index = i;
System.out.println("Enter a game players name: ");
names[index] = input.nextLine();
System.out.println("Enter the player's score: ");
scores[index] = input.nextDouble();
//used to check what the loop is doing each iteration
System.out.println(i);
}//end for
}//end main
}//end class