Recursion - digits in reverse order

前端 未结 15 1062
一向
一向 2021-01-15 10:32

I need to implement a recursive method printDigits that takes an integer num as a parameter and prints its digits in reverse order, one digit per line.

This is what

15条回答
  •  礼貌的吻别
    2021-01-15 10:45

    public static void reversDigits(long number) {
        System.out.println(number % 10);
        if (number >= 10) {
            reversDigits(number / 10);
        }
    }
    

    This is shortest/simplest version so far;)

提交回复
热议问题