您需要将代码放入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] + " "); } } }