Java编译错误,找不到符号

时间:2011-09-26 07:59:48

标签: java compiler-construction compiler-errors

获取错误“无法找到符号”,但我不知道我做错了什么。

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();
        }
    }
}

4 个答案:

答案 0 :(得分:3)

“for”循环后你有分号。

应该是这样的:

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

答案 1 :(得分: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();
        }
    }
}

答案 2 :(得分:1)

行中的最后一个分号

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

应该删除:

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

答案 3 :(得分:1)

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

这里你已经用一个分号结束了for循环,这导致在那一点终止循环。这就是为什么它显示它找不到符号 i ,因为它超出了for循环的范围。