📘 Lesson · Lesson 60
Floyds Triangle
Floyds Triangle
Print Floyd's Triangle in Java
Floyd's triangle prints consecutive numbers in a right-angled triangle shape.
Java Program
int num = 1, rows = 4;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num + " ");
num++;
}
System.out.println();
}
Output
1
2 3
4 5 6
7 8 9 10
How it Works
- A counter increases continuously across all rows.
- Row i prints i numbers.
Summary
- Floyd's triangle prints consecutive numbers in a right-angled triangle shape.
Print Floyd's Triangle in Java
Floyd's triangle consecutive numbers को right-angled triangle आकार में print करता है।
Java Program
int num = 1, rows = 4;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(num + " ");
num++;
}
System.out.println();
}
Output
1
2 3
4 5 6
7 8 9 10
कैसे काम करता है
- एक counter सभी rows में लगातार बढ़ता है।
- Row i में i numbers print होते हैं।
सारांश
- Floyd's triangle consecutive numbers को right-angled triangle आकार में print करता है।