The program is supposed to count from 0 to 19 and assign consecutive numbers, going through the matrix diagonally, as seen in the image:
I did it like this and it gives me the same result as in the image, but I don't think the method used is right.
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner leer=new Scanner(System.in);
int a[][]=new int [4][5];
for(int i=0;i<a.length;i++){
for(int j=0;j<a.length+1;j++){
a[1][0]=a[0][0]+1;
a[0][1]=a[1][0]+1;
a[2][0]=a[0][1]+1;
a[1][1]=a[2][0]+1;
a[0][2]=a[1][1]+1;
a[3][0]=a[0][2]+1;
a[2][1]=a[3][0]+1;
a[1][2]=a[2][1]+1;
a[0][3]=a[1][2]+1;
a[3][1]=a[0][3]+1;
a[2][2]=a[3][1]+1;
a[1][3]=a[2][2]+1;
a[0][4]=a[1][3]+1;
a[3][2]=a[0][4]+1;
a[2][3]=a[3][2]+1;
a[1][4]=a[2][3]+1;
a[3][3]=a[1][4]+1;
a[2][4]=a[3][3]+1;
a[3][4]=a[2][4]+1;
}
}
for(int i=0;i<a.length;i++){
System.out.println();
for(int j=0;j<a.length+1;j++){
System.out.print(a[i][j]+"\t");
}
}
}