scala mutable list

change all negative numbers to zero


object multableList {
  def main(args: Array[String]): Unit = {
        val lst = scala.collection.mutable.LinkedList(1,-2,7,-9)
      var cur = lst
    while (cur!=Nil){
      if(cur.elem<0) cur.elem = 0
      cur = cur.next
    }
    lst.foreach(println _)

  }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124723&siteId=291194637