Scala print between 1 and 100 is the sum of the number of multiples of 9

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/chen18677338530/article/details/91444258

Here Insert Picture Description

object Demo17 {
  def main(args: Array[String]): Unit = {
    var res = for (i <- 1 to 100 if i % 9 == 0) yield {
      i
    }

    var sum:Int = 0
    for (i<- res){
      sum += i
    }

    println("运算结果:"+res.length)
    println("运算结果:"+sum)
  }
}

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/chen18677338530/article/details/91444258