OneCompiler

FIRST DIAGONAL ARRAY

1631

public class Main {
public static void main(String[] args) {
int i;

    // Initialize the 2D array
    int a[][] = {{2, 4, 6}, {7, 9, 8}, {3, 4, 6}};

    System.out.println("First diagonal of matrix:"); 

    // Loop through the rows
    for (i = 0; i < 3; i++) { 
        // Print the diagonal element
        System.out.print(a[i][i] + " "); 
    }
    System.out.println(); // Move to the next line after printing the diagonal
}

}