Output digits of a positive integer

1, algorithm design:

class Method{
    public void digist(int n){
        if(n!=0){
            digist(n/10);
            System.out.println(n%10);
        }
    }
}

test:

public class Main {
    public static void main(String[] args) {
        Method method=new Method();
        method.digist(123);
    }
}

result:

 

 2, process analysis:

 

Guess you like

Origin www.cnblogs.com/zhai1997/p/11620132.html