2011-09-26 194 views
-1

獲取錯誤「不能Fin符號」,但我不知道我做錯了什麼。Java編譯錯誤,找不到符號

import java.util.Scanner; 

public class Exercise6_1{ 

    public static void main(String[] args){ 
     Scanner input = new Scanner(System.in); 
     System.out.print("Enter number of students: "); 
     int numberStudents = input.nextInt(); 
     int[] studentScores = new int[numberStudents]; 
     System.out.print("Enter " + numberStudents + " Scores: "); 
     for (int i = 0; i < numberStudents; i++);{ 
      studentScores[i] = input.nextInt(); 
     } 
    } 
} 
+0

添加完整的錯誤輸出。 –

回答

3

「for」循環後面有分號。

應該是這樣的:

for (int i = 0; i < numberStudents; i++) { 
    studentScores[i] = input.nextInt(); 
} 
1

你有一個;在for循環之後。

正確IMPL: -

import java.util.Scanner; 

public class Test { 
    public static void main(String[] args) { 
     Scanner input = new Scanner(System.in); 
     System.out.print("Enter number of students: "); 
     int numberStudents = input.nextInt(); 
     int[] studentScores = new int[numberStudents]; 
     System.out.print("Enter " + numberStudents + " Scores: "); 
     for (int i = 0; i < numberStudents; i++) 
     { 
      studentScores[i] = input.nextInt(); 
     } 
    } 
} 
1

在該行

for (int i = 0; i < numberStudents; i++);{ 

最後一個分號應刪除:

for (int i = 0; i < numberStudents; i++) { 
1
for (int i = 0; i < numberStudents; i++);{ 
     studentScores[i] = input.nextInt(); 
    } 

在這裏,你已經結束了對循環用一個分號,導致該點處的循環終止。這就是爲什麼它顯示它找不到符號,因爲它超出了for循環的範圍。