Priyanshu-Garg / CodeWorld

MIT License
8 stars 25 forks source link

Create Pattern1-Floyd's Triangle (in Java) using libraries #10

Closed ritikagarg0326 closed 2 years ago

ritikagarg0326 commented 2 years ago

import java.util.*; class floyd traingle{

public static void main(String[] args)
{
    // No of rows to be printed
    int n = 5;

    // Creating and initializing variable for
    // rows, columns and display value
    int i, j, k = 1;

    // Nested iterating for 2D matrix
    // Outer loop for rows
    for (i = 1; i <= n; i++) {

        // Inner loop for columns
        for (j = 1; j <= i; j++) {

            // Printing value to be displayed
            System.out.print(k + "  ");

            // Incremeting value displayed
            k++;
        }

        // Print elements of next row
        System.out.println();
    }
}

}