x
import java.util.Scanner;
import java.util.Stack;
public class TestNumTran {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入需要转换的数字:");
int num = scan.nextInt();
int ocNum = num;
Stack stack = new Stack();
int flag = 0;
while(num != 0) {
flag = num%2;
if(flag == 0 ) {
stack.push(0);
} else {
stack.push(1);
}
num = num/2;
}
System.out.print(ocNum + "转换成二进制为:");
while(!stack.empty()) {
System.out.print(stack.peek());
stack.pop();
}
}
}
书的下载地址:http://down.down3721.com/book/Javasjjgderban.rar