Created
March 11, 2019 05:29
-
-
Save maxjing/5e6e7f992c74c4babc6e370901918cae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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