This is another Java implementation of another more interesting 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
The Java code is implemented 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 ("Enter:");
Input = Integer.Parseint (STR);
IF (INPUT> 0 && Input { 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 not legal, must be between 1 ~ 10!"); } }