Hello!
Implement a method that finds the digonal of a matrix.Use the method as given;
static int[] diagonal(int[][] a) {..} the method should return the diagonal a in the form of an int array.
So what I've tried is this
test.java:8: error: illegal start of expressionpublic class test { static int[] diagonal (int[][] a) { for(int i = 0; i<a.length; i++) { for(int j = 0; i<a.length; j++) { if( i = j) { a =[i][j]; } } } return a; } public static void main(String[] args){ int[][] a = {{1,2,3,4}}; diagonal(a); } }
a =[i][j];
is the error I get when I try to compile.I think I know how to get the diagonal,we need 2 for loops to go through the array and we check the value if they match we found it. The part that is bugging me is I dont know how to transfer that into an int array and return it like I'm susposed to.
Any tips?