计算分数[Java程序]

计算分数[Java程序],java,arrays,procedural,Java,Arrays,Procedural,我的程序一直在为每个玩家累计分数,而不是将其分开。例如,如果第一个玩家得到3/5,第二个玩家得到2/5,则第二个玩家的分数显示为5。我知道答案可能很简单,但我无法在代码中找到它 首先谢谢 public static void questions(String[] question, String[] answer, int n) { String[] name = new String[n]; // Player Names int[] playerscor

我的程序一直在为每个玩家累计分数,而不是将其分开。例如,如果第一个玩家得到3/5,第二个玩家得到2/5,则第二个玩家的分数显示为5。我知道答案可能很简单,但我无法在代码中找到它

首先谢谢

public static void questions(String[] question, String[] answer, int n) {

        String[] name = new String[n];  // Player Names 
        int[] playerscore = new int[n]; // Argument for Score
        String[] que = new String[question.length]; //Questions for Loops
        int score = 0; // Declare the score


            /* --------------------------- For loop for number of players --------------------------- */ 
    for (int i = 0; i < n; i++)
    {
        name[i] = JOptionPane.showInputDialog("What is your name player"+ (i+1) +"?");
        JOptionPane.showMessageDialog(null,"Hello :"+ name[i] + " Player number " +(i+1)+ ". I hope your ready to start!");



            /* --------------------------- Loop in Loop for questions --------------------------- */ 
        for (int x=0; x<question.length; x++) {
            que[x] = JOptionPane.showInputDialog(question[x]);
                if(que[x].equals(answer[x]))
                    {

                        score = score +1;

                    }
        else {
                JOptionPane.showMessageDialog(null,"Wrong!");
             }

                } // End for loop for Question
playerscore[i] = score;
System.out.println("\nPlayer"+(i)+ "Name:"+name[i]+"\tScore"+score);
公共静态无效问题(字符串[]问题,字符串[]答案,int n){
String[]name=新字符串[n];//播放器名称
int[]playerscore=new int[n];//分数参数
String[]que=新字符串[question.length];//循环问题
int score=0;//声明分数
/*------------------------------------对于玩家数量的循环---------------------------*/
对于(int i=0;i对于(int x=0;x重置循环中的
score
变量,然后将其放置在
playerscore
的相应元素中。代码如下:

for (int i = 0; i < n; i++){
    name[i] = JOptionPane.showInputDialog("What is your name player"+ (i+1) +"?");
    JOptionPane.showMessageDialog(null,"Hello :"+ name[i] + " Player number " +(i+1)+ ". I hope your ready to start!");


    score = 0; //reset the score variable
    /* --------------------------- Loop in Loop for questions --------------------------- */ 
    for (int x=0; x<question.length; x++) {
        que[x] = JOptionPane.showInputDialog(question[x]);
        if(que[x].equals(answer[x])){
            score = score + 1;
            System.out.println("\nPlayer"+(i)+ "Name:"+name[i]+"\tScore"+score);
        }
        else{
            JOptionPane.showMessageDialog(null,"Wrong!");
        }
    } // End for loop for Question
    playerscore[i] = score; //assign the score for each player
}
for(int i=0;i