OneCompiler

2D Array lower Triangle matrix

1646

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

    // Declare and initialize the 2D array
    int a[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

    System.out.println("Lower triangle:");

    // Loop through the rows
    for (i = 0; i < 3; i++) { 
        // Loop through the columns
        for (j = 0; j < 3; j++) { 
            // Print the lower triangle
            if (i >= j) {
                System.out.print(a[i][j] + " "); // Print the element of the array
            }
        }
        System.out.println(); // New line after each row
    }
}

}