Java Program to Print Floyd Triangle

« Previous Program Next Program »

Print Floyd Triangle

To print the Floyd's triangle in Java programming, you have to use two for loops, the outer loop is responsible for rows and the inner loop is responsible for columns and start printing the Floyd's triangle as shown in the following program.

Java Programming Code to Print Floyd Triangle

As you know, Floyd’s triangle is a right angled-triangle using the natural numbers, so the following Java Program ask to the user to enter the range (upto how many line he/she want) to print the Floyd's Triangle upto the given range:

Following is the sample of Floyd's Triangle :

2 3
4 5 6
7 8 9 10
11 12 13 14 15

Following Java Program illustrates it:

/* Java Program Example - Print Floyd's Triangle */
import java.util.Scanner;

public class JavaProgram
    public static void main(String args[])
        int range, i, j, k=1;
        Scanner scan = new Scanner(;
        System.out.print("Enter Range (Upto How Many Line ?) : ");
        range = scan.nextInt();
        System.out.print("Floyd's Triangle :\n");
        for(i=1; i<=range; i++)
            for(j=1; j<=i; j++, k++)
                System.out.print(k + " ");

When the above Java Program is compile and executed, it will produce the following output:

Java Program print floyd triangle

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.