判断是否成年
object base15 {
def main(args: Array[String]): Unit = {
print("请输入你的年龄:")
var age = scala.io.StdIn.readInt()
if (age >= 18) {
println("成年人")
} else {
println("未成年人")
}
}
}
输入分数输出等级
输入正整数分数,输出对应的等级符号。规则如下:90,100 为 A 等;80,89 为 B 等;70,79 为 C 等;60,69 为 D 等;0, 59 为 E 等;
object Main {
def main(args: Array[String]): Unit = {
println("请输入正整数分数: ")
val score = scala.io.stdIn.readInt()
if (score >= 90 && score <= 100) {
println("A")
} else if (score >=80 && score <= 89) {
println("B")
} else if (score >=70 && score <= 79) {
println("C")
} else if (score >=60 && score <= 69) {
println("D")
} else if (score >=0&& score <= 59) {
println("E")
} else {
println("分数不在合理的范围之内!!!")
}
}
}
if语句的返回值
object Main {
def main(args: Array[String]) = {
//if语句的返回值
val a = if(2 > 1){
println("2>1是成立的")
"ok"
} else {
"no"
}
//判断一个是否为奇数,偶数
val num = 11
val reselt = if(num % 2 ==1){
"奇数"
} else{\
"偶数"
}
println(result)
}
}