题解 | #十进制数转二进制数#
十进制数转二进制数
http://www.nowcoder.com/practice/90d2de77e05e497eacc85e6b50272900
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
//write your code here......
int n = num;
String output = "";
String ans = "";
while(n > 0){
if(n % 2 == 0) output += "0";
else output += "1";
n /= 2;
}
for(int i = output.length() - 1; i >= 0; i--){
ans += String.valueOf(output.charAt(i));
}
if(num == 0) System.out.println(0);
else System.out.println(ans);
}
}