例题1:求两个数的较大者
object base27 {
def max(x:Int, y:Int):Int = {
val t = if(x >y) x else y
t
}
def say():Unit = {
println("hahahaha~~~")
}
def main(args: Array[String]): Unit = {
val rst = max(1,100)
println(s"${rst}")
}
}
例题2:求三个数的较大者
例题3:求三个数的最大值和最小值
def max(x:Int, y:Int, z:Int): (Int, Int) = {
var maxValue = if(x>y) x else y
maxValue = if(maxValue>z) maxValue else z
var minValue = if(x>y) y else x
minValue = if(minValue>z) z else minValue
(minValue, maxValue)
}
def main(args: Array[String]): Unit = {
val rst = max(1000,200,100)
println(s"最小值是:${rst._1}, 最大值是:${rst._2}")
}
}