如何在整数数组中保存标记?

时间:2021-01-04 15:59:19

I was trying to save the following line into different arrays:

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

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

The code I am using gives me integer values for year[i] but gives me zero values for winningScore[i], loosingScore[i] and crowd[i]. Can anyone help me please? My code is as follows:

我使用的代码给出了year [i]的整数值,但是给了我winsScore [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;
    }
}

1 个解决方案

#1


2  

== is use for equaling two reference and Object#equals method is use for equaling two Object.

==用于等于两个引用,而Object#equals方法用于等于两个Object。

if(held[i] == "Y") String equaling need to do with equals method like

if(hold [i] ==“Y”)String equaling需要用equals方法做

if(held[i].equals("Y")){...}

#1


2  

== is use for equaling two reference and Object#equals method is use for equaling two Object.

==用于等于两个引用,而Object#equals方法用于等于两个Object。

if(held[i] == "Y") String equaling need to do with equals method like

if(hold [i] ==“Y”)String equaling需要用equals方法做

if(held[i].equals("Y")){...}