标签:
package com.tydic.test /** * 除去数组中第一个负数以外的所有负数 */ object Test2 { def main(args: Array[String]): Unit = { val arr = Array(1, 2, 0, 3, 4, -1, -2, -3 ,0) var flag = 1 var index = 0 arr.map {e => if(flag > 0 ){ if(e >= 0){ index += 1 }else{ flag = -1 } } } var i = -1 arr.filter { x => i += 1 x >= 0 || i==index }.foreach { x => print(x+" ") } } }
标签:
原文地址:http://www.cnblogs.com/yudedipan/p/5213596.html