我需要实现一个递归方法printDigits,它以整数num作为参数,并以相反的顺序打印其数字,每行一位.
这是我到目前为止:
public class PrintDigits {
public static void main(String[] args) {
System.out.println("Reverse of no. is " + reversDigits(91));
}
/* Recursive function to reverse digits of num */
public static int reversDigits(int number) {
if (number == 0)
return number;
else {
return number % 10;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得我只缺少一行代码,但不确定我需要做些什么来修复它.