Answer to Question #40180 in Java | JSP | JSF for LostWind

Question #40180
Write a recursive method that converts a decimal integer to a binary string.
1
Expert's answer
2014-03-24T11:24:31-0400
public class IntegerToStringBinary {

public static void main(String argv[]){
int num = 105; //enter your integer number here
System.out.println(convertToBinary(num));
}

public static String convertToBinary(int number)
{
if(number > 0)
{
String str1 = new String(convertToBinary(number / 2));
String str2 = new String(str1+Integer.toString(number % 2));
return str2;
}

return "0";
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS