-1

我试图将以下行保存到不同的数组中:

1908,Souths,Easts,Souths,Cumberland,Y,14,12,4000

我使用的代码给了我整数值,year[i]但给了我零值winningScore[i]loosingScore[i]crowd[i]。任何人都可以帮助我吗?我的代码如下:

str[i] = inputFile.nextLine();
StringTokenizer tok = new StringTokenizer(str[i], ",");

while (tok.hasMoreTokens()) {   
    year[i] = Integer.parseInt (tok.nextToken());
    winteam[i] = tok.nextToken();    
    loosingteam[i] = tok.nextToken();
    minor[i] = tok.nextToken();
    wooden[i] = tok.nextToken();
    held[i] = tok.nextToken();
    if(held[i] == "Y") {
        winningScore[i] = Integer.parseInt (tok.nextToken()); 
        loosingScore[i] = Integer.parseInt (tok.nextToken());
        crowd[i] = Integer.parseInt (tok.nextToken());
    }
    else {
        break;
    }
}
4

1 回答 1

2

==是用于等于两个参考和Object#equals方法是用于等于两个Object

if(held[i] == "Y")字符串相等需要使用equals方法,例如

if(held[i].equals("Y")){...}
于 2013-05-17T05:49:23.717 回答