简体   繁体   中英

java.lang.AssertionError. How correctly fill an array through the loop. I do not know why my code does not work

public class CreateNewArray {
public static int[] createArray() {
int numbers[] = new int[5];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}return numbers;
}
}

The code does not work, please, help me to fix it.

Illegal modifier for the local class CreateNewArray; only abstract or final is permitted.

Well just remove the public.

class CreateNewArray {
  public static int[] createArray() {
    int numbers[] = new int[5];
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = i + 1;
    }return numbers;
  }
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM