输入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 }
浙公网安备 33010602011771号