Skip to content

Instantly share code, notes, and snippets.

@maxjing
Created March 11, 2019 05:29
Show Gist options
  • Save maxjing/5e6e7f992c74c4babc6e370901918cae to your computer and use it in GitHub Desktop.
Save maxjing/5e6e7f992c74c4babc6e370901918cae to your computer and use it in GitHub Desktop.
package com.JJ;
import java.util.Stack;
public class Main {
static Stack<Integer> nums;
public static void main(String[] args) {
binary(11);
while(!nums.isEmpty()){
System.out.printf("%d",nums.peek());
nums.pop();
}
}
public static Stack<Integer> binary(int n){
nums = new Stack<Integer>();
while(n/2!=0){
if(n%2==0)nums.push(0);
else nums.push(1);
n=n/2;
}
if (nums.peek()==0);
nums.push(1);
return nums;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment