import java.util.*;
public class Trans10_2{
//利用短除法+栈
public static void main(String[] args){
int N = 10;
int TYPE2 = 2;
Stack<Integer> stack = new Stack();
while(N != 0){
int mode = N % TYPE2;
// System.out.println("mode:"+mode);
stack.push(mode);
N = N / TYPE2;
}
// for (int i : stack) { //集合遍历方式, 0 1 0 1不符合要求
// System.out.print(i + " "); //错误的集合遍历:System.out.println(s.pop());
// }
while (!stack.empty()) {
System.out.println(stack.pop());
}
System.out.println();
}
}
转载于:https://my.oschina.net/datacube/blog/777239