-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP20_FloydsTriangle.java
More file actions
34 lines (30 loc) · 888 Bytes
/
Copy pathP20_FloydsTriangle.java
File metadata and controls
34 lines (30 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package programs;
/**
* ============================================================
* PROGRAM 20: Floyd's Triangle Pattern
* ============================================================
* Problem: WAP to print Floyd's Triangle of natural numbers.
*
* Example (n = 5):
* 1
* 2 3
* 4 5 6
* 7 8 9 10
* 11 12 13 14 15
* ============================================================
*/
public class P20_FloydsTriangle {
public static void printFloydsTriangle(int rows) {
System.out.println("=== FLOYD'S TRIANGLE (rows=" + rows + ") ===");
int currentNum = 1;
for (int r = 1; r <= rows; r++) {
for (int c = 1; c <= r; c++) {
System.out.printf("%-4d", currentNum++);
}
System.out.println();
}
}
public static void main(String[] args) {
printFloydsTriangle(5);
}
}