Java Program To Print Floyd’s Triangle
Chapter:
Miscellaneous
Last Updated:
10-08-2016 16:46:44 UTC
Program:
/* ............... START ............... */
import java.util.Scanner;
public class JavaFloydTriangle {
public static void main(String args[]) {
int rows, number = 1, counter, j;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows for floyd's triangle:");
rows = input.nextInt();
System.out.println("Floyd's triangle");
System.out.println("****************");
for (counter = 1; counter <= rows; counter++) {
for (j = 1; j <= counter; j++) {
System.out.print(number + " ");
number++;
}
System.out.println();
}
}
}
/* ............... END ............... */
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
Notes:
-
Floyd's triangle is a right-angled triangular array of natural numbers, used in computer science education.
- It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.
Tags
Print Floyd’s Triangle, Java