文档介绍:IT公司面试手册
Java十进制数换算二进制数(栈实现)
Java
import .*;
public class textBoard {
public Node head = null;
public static void main(String[] args){
String s = “”;
int num = 0;
textBoard board = new textBoard();
(“Please input a Decimal number : “);
//Input function!
try {
BufferedReader in = new BufferedReader(new InputStreamReader());
s = ();
num = (s);
}catch(IOException e) {}
(“Your entering Binary number is: ”+ (num));
}
public String swap(int i){
while(i != 1) {
Node node = new Node(i % 2);
push(node);
i = i / 2;
}
Node node1 = new Node(1);
push(node1);
String s = “”;
while(!isEmpty()){
s += ();
head = ();
}
return s;
}
public void push(Node element){
if(element != null){
(head);
head = element;
}
}
public boolean isEmpty(){
if(head == null){
return true;
}
return false;
}
}
class Node {
private int key = 0;
private Node next = null;
public Node(int i) {
= i;
= null;
}
public int getkey(){
return key;
}
public void setkey(int i){
= i;
}
public Node getnext(){
return next;
}
public void setnext(Node next){
= next;
}
}
.;
import .*;
import ;
import ;
import ;
import