Skip to content

Instantly share code, notes, and snippets.

@masious
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masious/b649824d0f292f2ecf14 to your computer and use it in GitHub Desktop.
Save masious/b649824d0f292f2ecf14 to your computer and use it in GitHub Desktop.
DS Questions - Question 2
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