java program to print floyds triangle

Programming Example

Write a program to print Floyd's triangle as shown below:

1

2  3

4  5  6

7  8  9  10

11 12 13 14 15

Solution

class Floyd
{
    public static void main(String arr[])
    {
        int a,b,c=1;
        for(a=1;a<=5;a++)
        {
            for(b=1;b<=a;b++)
            {
                System.out.print(c+"  ");
                c++;
            }
            System.out.println();
        }
    }
}
Output

1  

2  3  

4  5  6  

7  8  9  10  

11  12  13  14  15  

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad