利用栈转换二进制
package luyunzhou.one;
import java.util.Stack;
public class Bin {
public static void main(String[] args) {
// TODO Auto-generated method stub
int N = 50;
Stack<Integer> stack = new Stack<Integer>();
while(N>0){
stack.push(N%2);
N = N / 2;
}
int n = stack.size();
for (int i = 0; i < n; i++) {
System.out.print(stack.pop());
}
}
private static String parenthesisPatch(String str) {
Stack<String> exp = new Stack<String>();
for (int i = 0; i < str.length(); i++) {
String temp = str.charAt(i) + "";
String tempExp;
if (temp.equals(")")) {
String val2 = exp.pop();
String op = exp.pop();
String val1 = exp.pop();
tempExp = "(" + val1 + op + val2 + ")";
exp.push(tempExp);
} else {
exp.push(temp);
}
}
return exp.pop();
}
}