Java Program to Print Floyd’s Triangle

In this example, You learn about java program to print floyd's triangle. 

Here you learn print floyd's triangle in Java, You are given a number and the task of the program to print Floyd's Triangle.

Java Program to Print Floyd's Triangle

import java.util.Scanner;
public class FloydTriangle
{
 public static void main(String args[])
 {
    int n, num = 1, c, d;
    Scanner in = new Scanner(System.in);
    System.out.println("Enter the number of rows of floyd's triangle");
    n = in.nextInt();
    System.out.println("Floyd's triangle :-");
    for ( c = 1 ; c <= n ; c++ ) {
        for ( d = 1 ; d <= c ; d++ ) {
            System.out.print(num+" ");
            num++;
        }
        System.out.println();
    }
 }
}
Output

 
Enter the number of rows of floyd's triangle  
4

Floyd's triangle :-
1 
2 3 
4 5 6 
7 8 9 10

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form