import java.util.*;
import java.io.*;
class Mystack
{
LinkedList li=new LinkedList();
//在栈顶添加一个元素
public void push(Object o)
{
li.addFirst(o);
}
//移除元素
public Object pop()
{
return li.removeFirst();
}
//显示元素
public Object peek()
{
return li.getFirst();
}
//判断栈是否为空
public boolean isEmpty1()
{
return li.isEmpty();
}
/*public static void main(String args[])
{
Mystack ms=new Mystack();
ms.push("1");
ms.push("2");
ms.push("3");
while(ms.isEmpty1()==false)
{
System.out.println(ms.pop());
}
//System.out.println(ms.pop());
//System.out.println(ms.peek());
//System.out.println(ms.pop());
//System.out.println(ms.isEmpty1());
}*/
}
class JinzhiChange_test
{
Mystack ms;
int x;
int y;
int m;
int z;
JinzhiChange_test()throws IOException
{
InputStreamReader bos=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(bos);
System.out.println("请输入要转换的数:");
String ch=buf.readLine();
x=Integer.parseInt(ch);
System.out.println("请输入要转换的进制:");
String ch1=buf.readLine();
z=Integer.parseInt(ch1);
ms=new Mystack();
y=x;
}
void show()
{
while(x!=0)
{
m=x%z;
ms.push(m);
x=x/z;
}
}
void show1()
{
System.out.println(y+"的进制数为:");
while(ms.isEmpty1()==false)
{
System.out.print(ms.pop());
}
}
public static void main(String args[]) throws IOException
{
JinzhiChange_test ns=new JinzhiChange_test();
ns.show();
ns.show1();
}
}
|