1
動態片段2(i-1)
在內部for循環在以下常規碼?如果我用2i
或i+1
或任何硬編碼號碼(例如6
)works fine替換它。沒有方法簽名:java.lang.Integer.call()適用於參數類型:(java.lang.Integer)values:[1]
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)