I have a list:
val k = List(1,2,3,4,-69,78)
and would like to remove all negative elements in the list
I have the following code:
val k = List(1,2,3,4,-69,78)
val a = List()
for( k <- k){
         if(k > 0){
           a=a:+k
         }
      }
      println(a)
What it is supposed to run through the list and if an element in the list is positive, it should append it to another list in this case list a
however I get the following error:
ScalaFiddle.scala:9: error: reassignment to val a=a:+k ^
how can I fix this
Please note that I intentionally do not want to use l.filter.
If anyone has a better Idea as to how I can do this, it would be greatly appreciated
Thanks in advance
 
     
     
     
    