算法Sedgewick第四版-第1章基础-012一用stack实现输出一个数的二进制形式
1 @Test 2 public void e1_3_5() { 3 Stack<Integer> stack = new Stack<Integer>(); 4 int N = 7; 5 while (N > 0) { 6 stack.push(N % 2); 7 N = N / 2; 8 } 9 for (int d : stack) 10 StdOut.print(d); 11 StdOut.println(); 12 }
You can do anything you set your mind to, man!