开发者

Java Compile Error, cannot find symbol

Getting the error "Cannot Fin Symbol", but I don't know what I am doing wrong.

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 " + numberStu开发者_如何学Godents + " Scores: ");
        for (int i = 0; i < numberStudents; i++);{
            studentScores[i] = input.nextInt();
        }
    }
}


You have semicolon after the "for" cycle.

Should look like this:

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


you have an ; after the for loop.

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


The last semicolon in the line

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

should be removed:

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


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

Here You have ended the for loop with a semi-colon , which results in the termination of the loop at that point . That's why it shows it can't find symbol i , As it is out of the scope of the for loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜