Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sum(input: Array[Int]): Int = {
- var i=0;
- while(i<input.length) {
- sum=i+input(i);
- i=i+1;
- }
- sum
- }
- <console>:17: error: reassignment to val
- sum= (i+input(i))
- ^
- <console>:21: error: missing argument list for method
- sum Unapplied methods are only converted to functions when a function type is expected.
- You can make this conversion explicit by writing `sum _` or `sum(_)` instead of `sum`.
- <console>:17: error: reassignment to val
- sum=i+input(i);
- ^
- <console>:20: error: not enough arguments for method sum: (input: Array[Int])Int.
- Unspecified value parameter input.sum()
- def sum(input: Array[Int]): Int = input.sum
- val l = List(1,2,3,4,5)
- l.reduce((a,b) => a + b)
- l.foldLeft(0)((a,b) => a + b)
- def sum(l: List[Int]): Int = l match {
- case Nil => 0
- case head :: tail => head + sum(tail)
- }
- sum(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement