i would like some one expert to see my codes and tell my if there is another way to write this codes or can make any changes that leads to the same results




import java.util.Scanner;
public class answer {
public static void main(String args[]) {


Scanner in = new Scanner(System.in);

System.out.print("enter value: ");

int value = in.nextInt();
int num=0;


int i=0;
int j=0;
boolean upperCorner = false;
boolean lowerCorner = true;
int matrix[][]=new int[value][value];
while (num!=value*value){
matrix[i][j]=num++;



if ( (i == 0 && j != value -1 ) && lowerCorner ){
j++;
upperCorner = true;
lowerCorner = false;
}
else if ( (j == 0 && i != value -1 ) && upperCorner ){
i++;
lowerCorner = true;
upperCorner = false;
}
else if ( (j == value -1 ) && lowerCorner ){
i++;
lowerCorner = false;
upperCorner = true;
}
else if ( (i == value -1 ) && upperCorner ){
j++;
lowerCorner = true;
upperCorner = false;
}
else if (upperCorner ) {
j--;i++;
}
else if ( lowerCorner ) {
i--;j++;
}
}


for (i=0;i<value;i++){
for (j=0;j<value;j++){
System.out.printf("%5d",matrix[i][j]);
}
System.out.printf("\n");
}
}
}