题解 | #学生基本信息输入输出# Scala解法
学生基本信息输入输出
http://www.nowcoder.com/practice/58b6a69b4bf943b49d2cd3c15770b9fd
import scala.io.StdIn
object Main {
def main(args: Array[String]): Unit = {
val line: String = StdIn.readLine()
// 正则指定两种分隔符,用 | 隔开
val strs: Array[String] = line.split(";|,")
val id: String = strs(0)
val score1: Float = strs(1).toFloat
val score2: Float = strs(2).toFloat
val score3: Float = strs(3).toFloat
println("The each subject score of No. %s is %.2f, %.2f, %.2f.".format(id, score1, score2, score3))
}
}
查看2道真题和解析
