Last active
August 29, 2015 14:07
-
-
Save masious/b649824d0f292f2ecf14 to your computer and use it in GitHub Desktop.
DS Questions - Question 2
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 q2; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Main { | |
public static void main(String[] args) { | |
int a = 0; | |
try { | |
a = new Integer(new BufferedReader(new InputStreamReader(System.in)).readLine()).intValue(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
System.out.print(a + " = ( "); | |
String ans = ""; | |
while(a!=0){ | |
int b = a%2; | |
ans += b; | |
a /= 2; | |
} | |
System.out.println(new StringBuilder(ans).reverse().toString() + " )2"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment