带数组的令牌语法错误

Ioa*_*nou 0 java arrays

我是Java编程新手.我正在尝试编写一个程序来计算数字13的前400个倍数,并将它们存储在一个带有整数的数组中.我无法找到为什么这堂课有两个错误,我想我没有犯过任何错误.有人可以帮忙吗?第一个错误(此行上有三个错误)打开

System.out.println("the first 400 multiples of 13:" );
Run Code Online (Sandbox Code Playgroud)

令牌";"上的语法错误,{在此令牌之后的预期令牌上的
语法错误""13的前400个倍数:"",
在令牌上删除此令牌语法错误,错放的构造(s)

而第二个是在最后}

在哪里说:

语法错误,插入"}"以完成ClassBody

public class multiples_of_13 {
 int[] thirteens = new int[400];
 int numFound = 0;
 // candidate: the number that might be a multiple
 // of 13
 int candidate = 1;

 System.out.println("the first 400 multiples of 13:" );

 while (numFound < 400) {
     if (candidate % 13 == 0) {
         thirteens[numFound] = candidate;
         numFound++;
     }
     candidate++;
 }
 System.out.println("First 400 multiples of 13:");
 for (int i = 0; i < 400; i++) {
    System.out.print(thirteens[i] + " ");
 }
}
Run Code Online (Sandbox Code Playgroud)

Yas*_*jaj 6

您需要将代码放入main方法中,因为它是程序的输入.

在那个,指令不允许在类的主体内,但在其方法或块中.


public class multiples_of_13 {
    public static void main(String[] args) {
        int[] thirteens = new int[400];
        int numFound = 0;
        // candidate: the number that might be a multiple
        // of 13
        int candidate = 1;

        System.out.println("the first 400 multiples of 13:" );

        while (numFound < 400) {
            if (candidate % 13 == 0) {
                thirteens[numFound] = candidate;
                numFound++;
            }
            candidate++;
        }
        System.out.println("First 400 multiples of 13:");
        for (int i = 0; i < 400; i++) {
            System.out.print(thirteens[i] + " ");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)