Created
October 31, 2012 01:19
-
-
Save yao2030/3984239 to your computer and use it in GitHub Desktop.
use recursion to print out the binary representation of an integer
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
public class BP | |
{ | |
public static String binary(int N) | |
{ | |
if(N / 2 == 0) return "" + N; | |
return binary(N/2) + "" + N % 2; | |
} | |
public static void main(String[] args) | |
{ | |
int N = Integer.parseInt(args[0]); | |
String a = binary(N); | |
StdOut.println(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment