所以,在这里我试图从数组中取一些整数并将它们添加到每一行中。 然后我将这个总和存储为rowTotal。如果rowTotal大于maxRow .... 我累了。有人能指出明显吗?从2d数组中找出最高总数并在JAVA中打印
int maxRow = 0;
int playNum = 0;
for(int col = 0;col < score[0].length;col++)
maxRow += score[0][col];
for(int row = 1;row < score.length;row++)
{
int rowTotal = 0;
for(int col = 0;col < score[row].length;col++)
rowTotal += score[row][col];
if(rowTotal>maxRow)
{
playNum = row;
maxRow = rowTotal;
}
System.out.println("Player " + (playNum + 1) + " is victorious with a score of " + maxRow);
}
@ Ferret9,谢谢你让代码易读! – Hans