0

New to programming here and i keep getting the error message, 'incompatible types, int [] cannot be converted to int.

I have a very simple code and now I want to show a example of my error:

int[][] num = new int[2][2];
num[0][0]=1;
num[0][1]=2;
num[1][0]=3;
num[1][1]=4;
if (num[num[num[0][0]]].length >1)
    System.out.println("OK");

I've written a lot of code and can't change nested part (in if in this example) at all.

Help would be greatly appreciated.

dovetalk
  • 1,995
  • 1
  • 13
  • 21
Reza soumi
  • 19
  • 5
  • Welcome to Stackoverflow, Reza. It would help if you could provide detail on the line in question that gives the error. Also, have a look at this question and its answers. Multidimensional arrays in Java are not very straight-forward: https://stackoverflow.com/questions/12231453/syntax-for-creating-a-two-dimensional-array – dovetalk Mar 05 '20 at 03:03

1 Answers1

2

num[0][0] = 1

num[num[0][0]] = num[1] = [3, 4]

This means that

With num[num[num[0][0]]] you're trying to do num[[3,4]] which doesn't work in Java. Array index must be an int and in this case you're trying to pass an int array int[]

businesscasual
  • 755
  • 9
  • 14