次の Groovy コードの内側の for ループ2(i-1)
での動的スニペットの何が問題になっていますか? またはまたはハードコードされた番号(例)に置き換えると、正常に動作します。2i
i+1
6
1 class Algorithms {
2 static def printTriangle(n){
3 for(i in 1..n){
4 if(i>1){
5 for(j in 1..2(i-1)){ print 1 }
6 } else { print 1 } } //end of inner loop
7 println ""
8 } //end of outer loop
9 }
24 static def main(args){
26 printTriangles(4)
27 }
28 }
スタックトレースは
1
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call() is applicable for argument types: (java.lang.Integer) values: [1]
Possible solutions: wait(), any(), abs(), wait(long), wait(long, int), each(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call() is applicable for argument types: (java.lang.Integer) values: [1]
Possible solutions: wait(), any(), abs(), wait(long), wait(long, int), each(groovy.lang.Closure)
at Algorithm.printTriangle(Algorithm.groovy:5)
at Algorithm$printTriangle.callStatic(Unknown Source)
at Algorithm.main(Algorithm.groovy:26)