1

次の Groovy コードの内側の for ループ2(i-1)での動的スニペットの何が問題になっていますか? またはまたはハードコードされた番号(例)に置き換えると、正常に動作します2ii+16

  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)
4

1 に答える 1

0

ああ、私は数学をやっていませんでした。コードの動作に従っていました。

  for(j in 1..2*(i-1)){}
于 2013-10-18T16:33:23.423 に答える