/* Now that both are arrays are sorted just combine both to the scoreboard to send to players */
for(int k = 0; k < numCurrentPlayers; k++)
{
scoreBoard[k] = playerList[k] + " /" + pointTotals[k].toString();
System.out.println(playerList[k]);
System.out.println(pointTotals[k]);
System.out.println(scoreBoard[k]);
}
说playerList
is{"Player1","Player2"}
的内容和pointTotals
is{1,3}
和numCurrentPlayers
is的内容2
。
当我运行上面的代码时,生成的输出是:
播放器1
1
播放器1
播放器2
3
播放器2
为什么它不输出Player1 /1
或Player2 /3
在第三个打印语句上?
两个数组都被定义为私有静态类变量,它们由正在侦听传入数据包的其他线程更新。我的意思是这不是问题,当我在客户端收到数组的内容时,它们的内容是正确的。我只是不能像代码试图做的那样将它们结合起来。有什么想法吗?
编辑
/* The arrays to hold information for each connected user */
private static Integer[] pointTotals = new Integer[10];
private static String[] answers = new String[28];
private static BufferedImage[] images = new BufferedImage[28];
private static String[] scoreBoard = new String[10];
private static String[] playerList = new String[10];