Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def sum(input: Array[Int]): Int = {
  2. var i=0;
  3. while(i<input.length) {
  4. sum=i+input(i);
  5. i=i+1;
  6. }
  7. sum
  8. }
  9.  
  10. <console>:17: error: reassignment to val
  11. sum= (i+input(i))
  12. ^
  13. <console>:21: error: missing argument list for method
  14. sum Unapplied methods are only converted to functions when a function type is expected.
  15. You can make this conversion explicit by writing `sum _` or `sum(_)` instead of `sum`.
  16.  
  17. <console>:17: error: reassignment to val
  18. sum=i+input(i);
  19. ^
  20. <console>:20: error: not enough arguments for method sum: (input: Array[Int])Int.
  21. Unspecified value parameter input.sum()
  22.  
  23. def sum(input: Array[Int]): Int = input.sum
  24.  
  25. val l = List(1,2,3,4,5)
  26.  
  27. l.reduce((a,b) => a + b)
  28. l.foldLeft(0)((a,b) => a + b)
  29.  
  30. def sum(l: List[Int]): Int = l match {
  31. case Nil => 0
  32. case head :: tail => head + sum(tail)
  33. }
  34.  
  35. sum(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement