利用栈将十进制转换为二进制

import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Stack stack = new Stack();
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		while(N>0){
			int m = N%2;
			stack.push(m);
			N/=2;
		}
		
		while(!stack.isEmpty()){
			System.out.print(stack.pop());
		}
	}
}

你可能感兴趣的:(数据结构)