Stack.push(Object obj),not primitive int,try ues the correspend Wrapper class.

解决方案 »

  1.   

    你应该将其用类进行包装,如楼上所说,如果你想将整形压入栈中,可用Integer
      

  2.   

    kofwr(搭补流二) 我知道这里存在类型不兼容的问题,但如何解决。能说详细一些吗?我刚刚开始java,谢谢
    study_body(为什么总是长不大) 用Integer 也不可以,刚刚试过。
      

  3.   

    import java.util.*;
    public class  Conversion1
    {
       private int N,d,c,result;
       private String res=new String();
       private Stack s=new Stack();
       
        public void Init()  //获取要转换的数N,以及要转的进制树d
        {
         System.out.println("Please Input N");
         N=System.in.read();
         System.out.println("please Input d");
         d=System.in.read();
        }    public void Count()//进行转换
        {
        while ((c=System.in.read())=='\n')
      {
       while (N!=0)
       {
        result=N%d;
        s.push(result);
        N=N/d;
       }
      }
        }    public void Result()//输出转换结果
        {
             while (!s.isEmpty())
      {
       res=s.pop().toString();
       System.out.println(res);
        }
       }
    public static void main(String[] args) 
    {   Conversion1 st=new Conversion1();
      st.Init();
      st.Count();
      st.Result();
       }
    }
    还是不行,请问该怎样封装?????