这是现有代码如何修改可以实现输出如下
1 --> 1
3 --> 11
7 --> 111
15 --> 1111
30 --> 11110
61 --> 111101
Result: 61 -> 111101
public class BinaryRepresentation
{
public static int recur_depth = 0 ;
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
String output = ConvertToBinary(n);
System.out.printf("Result: %d -> %s\n", n, output);
}
public static String ConvertToBinary(int n){
if (n==0)
return "0";
else if (n==1)
return "1";
else {
return ConvertToBinary(n/2) + n%2;
}
}
}