Hey I'm really trying to convert decimal int to binary int, without succes.
Please help me.
And I don't want to make it 'System.out.println()' becuase I've already done it.
THANKS!
`I need recursive function that gets decimal int and return binary int
public static void decToBin(int number) {
if(number == 0)
return ;
decToBin(number / 2);
System.out.print(number % 2);
}
That it what I've done...
When I'm trying to get string:
public static String decToBin(int number) {
if(number == 0)
return "";
return new Integer(number % 2).toString() + new Integer(decToBin(number / 2)).toString();
}
Error...
System.out.println?Stringas result?StringBuilderwould be easier to work with.