Page 1 of 1

About Question enthuware.ocajp.i.v8.-2-.2015 :

Posted: Tue Apr 20, 2021 3:34 am
by BrentCoetzee
The answer would give an java.lang.ArrayIndexOutOfBoundsException: 5

Re: About Question enthuware.ocajp.i.v8.2.2015 :

Posted: Tue Apr 20, 2021 3:45 am
by BrentCoetzee
I believe the answer should be:

int[][] matrix = new int[5][4];
for(int i=0;i<5; i++) matrix[1]  = 1;

Re: About Question enthuware.ocajp.i.v8.2.2015 :

Posted: Tue Apr 20, 2021 4:10 am
by admin
Why do you believe so? Specifically, what makes you think that matrix[1] = 1; is valid?
Try compiling and running the code exactly as given in the question/option.

Re: About Question enthuware.ocajp.i.v8.2.2015 :

Posted: Tue Apr 20, 2021 11:16 am
by BrentCoetzee
Apologies, there should be before [1]

Re: About Question enthuware.ocajp.i.v8.2.2015 :

Posted: Tue Apr 20, 2021 11:19 am
by BrentCoetzee
When posting a square bracket with letter i inside,it is removed as soon as i submit the post.

Re: About Question enthuware.ocajp.i.v8.2.2015 :

Posted: Tue Apr 20, 2021 11:21 am
by BrentCoetzee
Apologies, I made a mistake the answer to the question is correct in your material. DUH moment for me.