一个函数/方法在函数/方法体内又调用了本身,我们称之为递归调用

    递归算法
    1) 方法调用自身
    2) 方法必须要有跳出的逻辑
    3) 方法调用自身时,传递的参数应该有规律
    4) scala中的递归必须声明函数返回值类型

    1. object TestFunction {
    2. def main(args: Array[String]): Unit = {
    3. // 阶乘
    4. println(test(5))
    5. }
    6. def test( i : Int ) : Int = {
    7. if ( i == 1 ) {
    8. 1
    9. } else {
    10. i * test(i-1)
    11. }
    12. }
    13. }