因此,我试图遍历2d数组的行以检查该行是否与方法的属性匹配。如何使用if来检查行?这是我的代码
public void recordWhiplashPoints(ConnectionToClient client, int vote){
int[][] votecount = new int[game.getPlayers().length][0];
outside:
if(game.getRecordedAnswers() <= game.getPlayers().length){
for (int i = 0; i < game.getPlayers().length; i++) {
for (int q = 0; q < votecount.length; q++) {
if(votecount[q] == vote){
//do stuff
}
}
}
}
}
因此,votecount [row]在哪里。我可以将其与财产投票进行一些比较吗?
最佳答案
因此,对于二维数组(基本上只是数组数组),您将使用votecount[i]
之类的成员数组,而使用votecount[i][q]
获得该数组的成员。我认为以下是您想要的代码:
int[][] votecount = new int[game.getPlayers().length][0];
outside:
if(game.getRecordedAnswers() <= game.getPlayers().length){
for (int i = 0; i < length; i++) {
// note that we need to compare against the array votecount[i]
for (int q = 0; q < votecount[i].length; q++) {
// here we access the actual element votecount[i][q]
if(votecount[i][q] == vote){
//do stuff
}
}
}
}