2014-10-19 45 views
-1

我試圖找出Eclipse中這段代碼有什麼問題。我結束了錯誤信息fruit cannot be resolved to a variable,但在我正在觀看的教程中,他的代碼就像這樣寫的,它顯示的數組沒有問題。有什麼建議?這裏是鏈接到教程https://www.udemy.com/java-tutorial/#/lecture/135354Java無法解析我的變量

public class ArraysofStrings { 
    public static void main(String[] args) { 
     String[] words = new String[3]; 

     words[0] = "Hello "; 
     words[1] = "To "; 
     words[2] = "You"; 

     String[] foods = {"apple", "bannana", "kiwi", "pear"}; 

     for (String fruit: foods); { 
      System.out.println(fruit); 
     } 
    } 
} 
+0

你有一個不需要的分號'for(String fruit:foods);'。刪除它,你應該沒問題。 – 2014-10-19 22:00:53

回答

4

for (String fruit: foods); 

去掉 「;」