title | date | draft | tags | categories | |||
---|---|---|---|---|---|---|---|
Algorithm4 Java Solution 1.3.05 |
2019-07-04 05:47:10 +0800 |
false |
|
|
What does the following code fragment print when N is 50? Give a high-level description of what it does when presented with a positive integer N.
show the binary string representation of integer N.
public static void showBinaryN(int N) {
_VarySizedCapacityStack<Integer> stack = new _VarySizedCapacityStack<>();
while (N > 0) {
stack.push(N % 2);
N = N / 2;
}
for (int d :
stack) {
StdOut.printf("%d", d);
}
StdOut.println();
}