Foundations
Functions
Functions name reusable work and return values to the caller.
Functions
Functions.scala
object Main {
def square(value: Int): Int = {
value * value
}
def main(args: Array[String]): Unit = {
val side =
val area = square(side)
println("side=" + side)
println("area=" + area)
}
}
object Main {
def square(value: Int): Int = {
value * value
}
def main(args: Array[String]): Unit = {
val side =
val area = square(side)
println("side=" + side)
println("area=" + area)
}
}
object Main {
def square(value: Int): Int = {
value * value
}
def main(args: Array[String]): Unit = {
val side =
val area = square(side)
println("side=" + side)
println("area=" + area)
}
}
function call
A function call runs the named function and can use the returned value in another expression.