Floyd’s triangle in Java
Here, you will learn and get the program code of the Floyd triangle in Java programming.
Floyd’s triangle is a right-angled triangular array of natural numbers. It is named after Robert Floyd, who invented it in the 1960s. Floyd’s triangle Example:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Program of floyd’s triangle in java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //Floyd's triangle program in java import java.util.*; public class FloydsTriangle { public static void main(String ar[]) { int rows , num = 1; Scanner sc = new Scanner(System.in); System.out.print("Enter number of rows : "); rows = sc.nextInt(); System.out.println("\n"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(num + " "); num++; } System.out.println(); } } } |
Output
Check out our other Java Programming Examples