Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

Write a Java program to print Floyd’s triangle?

Floyd's triangle is a right-angled triangular pattern arranged in rows of numbers from 1 to n. Using Nested loops, you can create Floyd's triangle with Java that consists of two loops: an outer loop that controls rows and an inner loop that controls columns.

Each number in Floyd's triangle equals the sum of the two numbers above it.


1

2 3

4 5 6

7 8 9 10

Here is the Java program that prints Floyd’s triangle.


import java.util.Scanner;
 
 class FloydTriangle
 {
    public static void main(String args[])
    {
       int num1, num2 = 1, i, j;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the number of rows for Floyd's Triangle");
       num1 = sc.nextInt();
       System.out.println("Floyd's Triangle:");
       for ( i = 1; i <= num1; i++ )
       {
          for ( j = 1; j <= 1; j++ )
            {
               System.out.print(num2+" ");
               num2++;
            }
           System.out.println();
       }
    }
 }
 

Output:


Enter the number of rows for Floyd's Triangle
5


Floyd's Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud