Answer to Question #40180 in Java | JSP | JSF for LostWind
Write a recursive method that converts a decimal integer to a binary string.
1
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!
Learn more about our help with Assignments:
JavaJSPJSF
Comments
Leave a comment