输入123,打印1 2 3(两种方法)

 1 import java.util.Scanner;
 2 public class test72 {
 3     /**
 4      *
 5      * @param args
 6      */
 7     public static void num(int n) {
 8         if(n > 9) {
 9             num(n/10);
10         }
11         System.out.println(n%10);
12     }
13     public static void main(String[] args) {
14         Scanner scan = new Scanner(System.in);
15         int n = scan.nextInt();
16 
17         while(n != 0) {
18             int a = n %  10;
19             System.out.println(a);
20             n /= 10;
21         }
22         num(123);
23     }
24 }

 

posted @ 2020-04-28 11:17  听说在北郭  阅读(852)  评论(0)    收藏  举报