Floyd’s triangle is a right-angled triangular array of natural numbers,It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner. It is named after Robert Floyd.
Program To Print Floyd’s Triangle in Java
class PrintFloydTriangle { public static void floydTriangle(int n) { int j, k, num = 1; for (j = 1; j <= n; j++) { for (k = 1; k < j + 1; k++) { System.out.print(num++ + " "); } System.out.println(); } } public static void main(String[] args) { floydTriangle(6); } }
Output:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21