Functions and Methods
Parameters and Returns
Pass two values into a method and use its return value.
Parameters and Returns
ParametersReturns.scala
object Main {
def area(width: Int, height: Int): Int = {
width * height
}
def main(args: Array[String]): Unit = {
val width =
val height = 4
val result = area(width, height)
println("width=" + width)
println("height=" + height)
println("area=" + result)
}
}
object Main {
def area(width: Int, height: Int): Int = {
width * height
}
def main(args: Array[String]): Unit = {
val width =
val height = 4
val result = area(width, height)
println("width=" + width)
println("height=" + height)
println("area=" + result)
}
}
parameters-returns
Parameters carry values into a method. The return value carries the result back to the caller.