Guest User

Untitled

a guest
May 17th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. object OperatorOverRange {
  2. def operateOverRange(f: Int => Int)(operate: (Int, Int) => Int)(base: Int)(a: Int, b:Int): Int =
  3. if (a > b) base else operate(f(a), operateOverRange(f)(operate)(base)(a + 1, b))
  4.  
  5. def main(args: Array[String]) {
  6. println("Sum of range of numbers from 3 to 8 is: " + operateOverRange(x => x)((x,y) => x + y)(0)(3,8))
  7. println("Product of range of numbers from 3 to 8 is: " + operateOverRange(x => x)((x,y) => x * y)(1)(3,8))
  8. }
  9. }
Advertisement
Add Comment
Please, Sign In to add comment