Matrix
Hello everyone. I have been trying to solve this Matrix program wherein if user enters 4, it will generate 16 numbers; if 3, it will generate 9 numbers. I am struggling on the else-if statements. The output must be arranged just like this: 16 15 14 13 9 10 11 12 8 7 6 5 1 2 3 4 This is my current program: import java.util.Scanner; public class Matrix { public static void main(String[] args) { Scanner mtrx = new Scanner(System.in); int matrixNum = 4; int row, col; int ai = 0, deductor = 0, adder = 1; System.out.print("Enter matrix to generate (n by n): "); matrixNum = mtrx.nextInt(); for(row = 1; row <= matrixNum; row++) { for(col = 1; col <= matrixNum; col++) { if(col == 1) { ai = matrixNum*matrixNum - deductor; }else if((col % 2) == 0) { ai = matrixNum*col - deductor; }else { ai += adder; } System.out.print(ai + "\t"); } System.out.println(); deductor = deductor + matrixNum; adder +=2; } } }