Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Floyds-triangle/Groovy/floyds-triangle.groovy
Normal file
21
Task/Floyds-triangle/Groovy/floyds-triangle.groovy
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Floyd {
|
||||
static void main(String[] args) {
|
||||
printTriangle(5)
|
||||
printTriangle(14)
|
||||
}
|
||||
|
||||
private static void printTriangle(int n) {
|
||||
println(n + " rows:")
|
||||
int printMe = 1
|
||||
int numsPrinted = 0
|
||||
for (int rowNum = 1; rowNum <= n; printMe++) {
|
||||
int cols = (int) Math.ceil(Math.log10(n * (n - 1) / 2 + numsPrinted + 2))
|
||||
printf("%" + cols + "d ", printMe)
|
||||
if (++numsPrinted == rowNum) {
|
||||
println()
|
||||
rowNum++
|
||||
numsPrinted = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue