This is another interesting JAVA Implementation of the matrix.
When N = 4, the output is as follows:
1 2 5 10
4 3 6 11
9 8 7 12
16 15 14 13
Java code implementation is as follows:
Import javax. Swing. joptionpane;
Public class Test2
{
Public static void main (string [] ARGs)
{
String STR;
Final int max = 10;
Int input;
Int D, I, j, M;
Int A [] [] = new int [10] [10];
STR = joptionpane. showinputdialog ("input :");
Input = integer. parseint (STR );
If (input> 0 & input <max)
{
I = 1;
J = 1;
M = 1;
D = 1;
For (I = 1; I <= input; I ++)
{
For (j = 1; j <= I; j ++)
{
A [J] = m ++;
If (j = I)
For (D = J-1; D> = 1; d --)
A [J] [d] = m ++;
}
}
System. Out. println ("output :");
System. Out. println ();
For (I = 1; I <= input; I ++)
{
For (j = 1; j <= input; j ++)
{System. Out. Print ("" + A [J] + "");}
System. Out. println ();
}
}
Else
System. Out. println ("the number of inputs is invalid. It must be 1 ~ Between 10! ");
}
}