当字符串标记是 int 时,我的代码似乎不起作用。这里是:
public class CO2Data {
CO2Data dataSet[] = new CO2Data[10];
String strLine = "Italy 476.08 116.86 2 592";
int lines = 10;
double roadCO2;
public void saveLineInfo(String strLine, int lines) {
StringTokenizer token = new StringTokenizer(strLine);
String str = "hello";
int count = 0;
for (int i = 0; i < lines; i++) {
while (token.hasMoreTokens()) {
str = token.nextToken();
if (count == 3) {
getRoadCO2(str, roadCO2);
dataSet[i].setRoadCO2(roadCO2);
}
count++;
}
}
}
public double getRoadCO2(String str, double roadCO2) {
roadCO2 = Double.parseDouble(str);
return roadCO2;
}
public void setRoadCO2(double roadCO2) {
this.roadCO2 = roadCO2;
}
}
在其余的行中,roadCO2 是双倍的,所以我猜我的程序很混乱?我如何解决它?非常感谢!