-2

enter image description here

I am not sure if my logic works, as I already change x to x+1 in my for loop condition.

In addition, why I can only put it in the main body but I can't put this piece of code:

    multiArray[0] = new int [0];
    multiArray[1] = new int [1];
    multiArray[2] = new int [2];
    multiArray[3] = new int [3];

below this code: public static int[][] multiArray = new int[4][];

This is what happens: enter image description here

What it says is that: Exception in thread "main" java.lang.Error: Unresolved compilation problem and syntax error on token "void", record expected

Btw, it suddenly pops out squiggly red lines on 'void' and syntax errors like add class body after';'.

I am really stuck, thank you.

Nayuki
  • 17,911
  • 6
  • 53
  • 80
Copo
  • 7
  • 1
  • 4
    [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – shmosel Aug 16 '23 at 04:08
  • 2
    An array defined as `new int[0];` does not contain any elements. You are trying to access `multiArray[0][0]`, which is out of bounds, just as the error says. If you want one element, numbered 0, you need `new int[1];`. – Tim Roberts Aug 16 '23 at 04:11
  • 1
    You're not declaring your nested (or "2D") array correctly. There is no "index out of bounds exception" to be found here, since you don't even yet have compilable code. Never try to run code that doesn't compile. – Hovercraft Full Of Eels Aug 16 '23 at 04:12

0 Answers0