我只有循環1次是什麼問題的for循環方法有麻煩?在數組中完全沒有問題,它能夠打印我想要的值。For循環僅循環1次JAVA?
這裏是我的代碼:", "
public static void main(String[] args){
String s = "Apple0, Apple1, Apple2, Apple3, Apple4";
String[] word = s.split(",");
StringBuffer str = new StringBuffer();
Integer total = 0;
for (int y = 0; y < word.length; y++){
if(word[y].toString().equals("Apple2")){
total++;
//str.append(word[y].toString());
}else if(word[y].toString().equals("Apple3")){
total++;
//str.append(word[y].toString());
}else if(word[y].toString().equals("Apple4")){
total++;
//str.append(word[y].toString());
}
else if(word[y].toString().equals("Apple1")){
total++;
//str.append(word[y].toString());
}
}
System.out.println(word[0] + word[1] + word[2] + word[3] + word[4] + word.length);
System.out.println(str + "hihi" + total);
}
爲什麼在一個已經是字符串的對象上調用'.toString()'? – 2013-02-25 03:24:32
我的錯誤,但我刪除它的循環仍然循環1次?任何解決方案 – cchua 2013-02-25 03:26:22