package test33
import scala.collection.mutable.ListBuffer
import scala.io.Source
case class Student(name:String,yumen:Int,shuxue:Int,yingyu:Int,total:Int,ang:Int)
object test {
def main(args: Array[String]): Unit = {
val list=ListBuffer[Student]()
val it=Source.fromFile("score.txt").getLines().drop(1)
val shuxuezongfen=0
while (it.hasNext){
val content=it.next()
val 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
list+=Student(name,yuwen,shuxue,yingyu, total,avg )
println("数学平均分",shuxuezongfen/list.length)
val orderList=list.sortWith((a,b)=>a.total>b.total).slice(0,3)
orderList.foreach(s=>println(s"姓名:${s.name},总分:${s.total}"))
list.sortWith((a,b)=>a.shuxue>b.shuxue)
.foreach(s=>println(s"姓名:${s.name},数学:${s.shuxue},总分:${s.total}"))
}
}
}
scala字符串
最新推荐文章于 2025-12-21 15:55:57 发布
1097

被折叠的 条评论
为什么被折叠?



