1斐波那契;
public int foo(int n){
return n==1||n==2?:foo(n-1)+foo(n-2);
}
2.把十進制轉二進制字元串
public String foo(int n){
return n/2<0?n%2:foo(n/2)+n%2;
}
3.求一個數的喝,如123456 1+2+3+4+5+6 =21, 2+1 = 3
直到和為一位數時
public int foo(int n ){
if(n/10<0)
{
return n;
}
else{
int sum =
return
}
}
private int foo1(int n){
return n/10<0?n:foo1(n/10)+n%
}
轉載于:https://www.cnblogs.com/xianghong/p/4515536.html