forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloydTriangle.java
More file actions
30 lines (25 loc) · 768 Bytes
/
FloydTriangle.java
File metadata and controls
30 lines (25 loc) · 768 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
package com.thealgorithms.others;
import java.util.ArrayList;
import java.util.List;
final class FloydTriangle {
private FloydTriangle() {
}
/**
* Generates a Floyd Triangle with the specified number of rows.
*
* @param rows The number of rows in the triangle.
* @return A List representing the Floyd Triangle.
*/
public static List<List<Integer>> generateFloydTriangle(int rows) {
List<List<Integer>> triangle = new ArrayList<>();
int number = 1;
for (int i = 0; i < rows; i++) {
List<Integer> row = new ArrayList<>();
for (int j = 0; j <= i; j++) {
row.add(number++);
}
triangle.add(row);
}
return triangle;
}
}