>Let me know if it works
If you tested it then you would find out that it accesses your arrays out of bounds.
>Narue can u explain to me why i would initialize row to matrix.length-1?
Arrays in Java are zero based, which means that the indices go from 0 to length-1. If you initialize the index variable to matrix.length then you'll be accessing the array out of bounds and it will throw an exception. Consider this array:
The first item is 7 at a[0]. The fifth item is 1 at a[4]. a.length evaluates to 5, so what happens when you do this?
public class ja {
public static void main(String[] args)
{
int[] a = {7,3,5,8,1};
System.out.println(a[5]);
}
}
Now what happens when you do the same thing in a different way?
public class ja {
public static void main(String[] args)
{
int[] a = {7,3,5,8,1};
System.out.println(a[a.length]);
}
}
Now, just for grins, try this and see how it gives you the last item in the array:
public class ja {
public static void main(String[] args)
{
int[] a = {7,3,5,8,1};
System.out.println(a[a.length - 1]);
}
}
That's why I used matrix.length-1.