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)
  }
  }
}
相关推荐
青柠代码录几秒前
【MySQL】事务:如何使用事务
后端
猫墨*几秒前
springboot3、knife4j-openapi3配置动态接口版本管理
java·开发语言
weixin_531651811 分钟前
Python 渐进式学习指南
开发语言·windows·python
weixin_649555673 分钟前
C语言程序设计第四版(何钦铭、颜晖)第八章指针之在数组中查找指定元素
c语言·开发语言
add45a7 分钟前
C++中的原型模式
开发语言·c++·算法
代码s贝多芬的音符7 分钟前
Android NV21 转 YUV 系列格式
android·开发语言·python
2401_844221328 分钟前
C++类型推导(auto/decltype)
开发语言·c++·算法
2201_753877799 分钟前
高性能计算中的C++优化
开发语言·c++·算法
无限进步_9 分钟前
深入解析C++容器适配器:stack、queue与deque的实现与应用
linux·开发语言·c++·windows·git·github·visual studio
2501_945425159 分钟前
分布式系统容错设计
开发语言·c++·算法