面试题:用java编程,在不适用循环变量的条件下,给正整数n,以2n,4n,8n...8n,4n,2n的方式输出,当大于5000时,以特定的方式输出:
比如n=1234,输出结果为:
1234,
2468,
4936,
9872,
9872,
4936,
2468,
1234...
public class Blen{
public static void main(String[] args){
doubleN(1234);
}
public static void doubleN(int n){
if(n<=5000){
System.out.println(n);
doubleN(2*n);
if(2*n>5000){
System.out.println(2*n);
}
System.out.println(n);
}
}
}