Reza soumi
Reza soumi

Reputation: 19

nested part of incompatible type

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.

Upvotes: 0

Views: 21

Answers (1)

businesscasual
businesscasual

Reputation: 755

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[]

Upvotes: 2

Related Questions