请教数据结构中栈的用法
我的目的是:把十进制的9转化成2进制的形式,因为转化规则除二取余,直到商为零为止,倒排
import java.io.*;
import java.util.Stack;
public class my10to2 {
public static void main(String[] args){
int m=9;
Stack stk=new Stack();
do{
if(m%2==0) stk.push("0");
else stk.push("1");
m=m/2;
}while(m!=1||m!=0);
while(!stk.empty())
System.out.println(stk.pop());
}
}
编译结果为:
Note: G:\JavaBar\JCroJ\my10to2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Process completed.
运行结果为:请高手指教一下!
Exception in thread "main" java.lang.OutofMemoryError:Java heap space