0
How do I complete this?
What do I put after the return? If I put y, if gives me zero. I can't put b as I understand it. Or is this code incomplete? https://code.sololearn.com/cjz1jlR561ho/?ref=app
4 Answers
+ 7
Mayur Gowda You need to return String. Every time you are reinitialising b so how you can get actual result. You need to declare b outside the loop.
public static String toBinary(int y)
{
String b="";
while(y>0)
{
b=(y%2)+b;
y/=2;
}
return b;
}
+ 2
it wouldn't if you change the return type of the method too.
public static String toBinary(int y)
+ 1
Right... Thanks Bahhađ§. I didn't realize that I Am Groot ! had written the same thing as well. Thanks to both of you. Much appreciated for the help.
0
I Am Groot !, But doesn't that give an error saying, string cannot be converted to int.