一、将一个数字顺序输出
例如:数字1013
public class PrintNum{
public static void main(String[] args) {
int num=1013;
printNumber(num);
}
public static void printNumber(int num){
if(num > 9){
printNumber(num / 10);
}
System.out.println(num % 10);
}
}
二、 输入一个非负整数,返回组成它的数字之和.
public class Test{
public static int sum = 0;
public static void main(String[] args) {
int num = 1654;
int ret= toFind(num);
System.out.println("ret="+ret);
}
public static int toFind(int num){
if(num > 9){
toFind(num / 10);
}
sum += num % 10;
return sum;
}
}