栈的应用
除二取余,逆序排列
package _1_3linkedList;
import java.util.Scanner;
/*打印N的二进制表示
*/
public class BinaryRepresentation
{
public static void main (String[] args)
{
Stack<Integer> stack=new Stack<Integer>();
Scanner sc=new Scanner(System.in);
Integer n=sc.nextInt(); /*n也可为int类型*/
while(n>0)
{
stack.push(n%2);
n=n/2;
}
for(int i:stack)
System.out.print(i);
sc.close();
}
}
33
100001