Scala计算重过载次数

import scala.collection.mutable.ArrayBuffer
/**
 * 计算重过载次数
 * 连续三个数超过3记次数1,计算总次数
 */
object HelloWorld {
  def main(args: Array[String]): Unit = {
    var dataArray = Array(7, 9, 33, 44, 11, 12, 34, 14, 23, 21, 20, 65, 33, 15, 16)
    val dataArrayBuffer = dataArray.toBuffer
    var totalCount = 0;
    var length = dataArrayBuffer.length
    for (i <- 0 until length) {
      if (dataArrayBuffer.length >= 3) {
        if (dataArrayBuffer(0) >= 12 && dataArrayBuffer(0 + 1) >= 12
          && dataArrayBuffer(0 + 2) >= 12) {
          totalCount += 1;
          dataArrayBuffer.remove(0, 3)
        } else {
          dataArrayBuffer.remove(0, 1)
        }
      }
    }
    println("总次数为:" + totalCount)
  }
}

你可能感兴趣的:(scala)