請問一下,下面要如何改,才能夠讓 res23: Int = 110
scala> def totalResultOverRange(number: Int, codeBlock: (Int)=>Int=(x)=>2*x )
| : Int = {
| var result = 0
| for ( i <- 1 to number ) {
| result += codeBlock(i)
| }
| result
| }
totalResultOverRange: (number: Int, codeBlock: Int => Int)Int
scala>
| totalResultOverRange(10, t => t )
res23: Int = 55
def totalResultOverRange(number: Int, codeBlock: (Int)=>Int)
: Int = {
var result = 0
for ( i <- 1 to number ) {
result += codeBlock(i)
}
result
}
totalResultOverRange(10, t => 2*t )