Bootstrap

Scala中字符串

package test_33

import scala.io.Source
//成绩分析
object test {
  def main(args: Array[String]): Unit = {
    //1.读入成绩,按行去读取
   val it= Source.fromFile("score.txt").getLines().drop(1)
    while (it.hasNext){
      val content=it.next()
    //使用中文的逗号去拆分字符串
      var arr=content.split(",")
      val name=arr(0)
      val yuwen=arr(1).toInt
      val shuxue=arr(2).toInt
      val yingyu=arr(3).toInt
      val total=yuwen+shuxue+yingyu
      val avg=total / 3
      println("当前行是",name,yingyu,total)
  }
  }
}
;