获取错误“无法找到符号”,但我不知道我做错了什么。
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 :(得分:1)
纠正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循环的范围。