This java program prints Floyd's triangle. In this Floyd triangle there are n integers in the nth row and a total of (n(n+1))/2 integers in n rows.

'/>

Write a java program draw a Floyd's triangle ?

This java program prints Floyd's triangle. In this Floyd triangle there are n integers in the nth row and a total of (n(n+1))/2 integers in n rows.


								
import java.util.Scanner;

/**
 *
 * @author Mindclues
 */
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 you draw");
        n = in.nextInt();

        System.out.println("Floyd's triangle are:-");

        for (c = 1; c <= n; c++) {
            for (d = 1; d <= c; d++) {
                System.out.print(num + " ");
                num++;
            }

            System.out.println();
        }
    }
}

							

								
Enter the number of rows of floyd's triangle you draw
6
Floyd's triangle are:-
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
							

Related Articles

post a comment