중첩 메소드
def factorial(x: Int): Int = {
def fact(x: Int, accumulator: Int): Int = {
if (x <= 1) accumulator
else fact(x - 1, x * accumulator)
}
fact(x, 1)
}
println("Factorial of 2: " + factorial(2))
println("Factorial of 3: " + factorial(3))
def factorial(x: Int): Int =
def fact(x: Int, accumulator: Int): Int =
if x <= 1 then accumulator
else fact(x - 1, x * accumulator)
fact(x, 1)
println("Factorial of 2: " + factorial(2))
println("Factorial of 3: " + factorial(3))
→ 메소드 정의를 중첩할 수 있다.