0
Can I get some help? I have been trying to solve the Java course Binary Converter Code Project for 2 weeks now.
https://code.sololearn.com/c5wBz5Up7Ve5/?ref=app I want to return the binary of x, but it doesn't run at all. It says "invalid method declaration;return type required"
11 Respuestas
+ 3
This error occurs because your toBinary method returns an integer but you didn’t put the declaration before the function name. It should be:
Public static int toBinary
However, you shouldn’t return your num variable, but binary variable.
So the method should be: public static String toBinary
return binary;
+ 2
Wheew alright thanks a lot!
+ 1
O ok thanks, however...Even though it runs now, it only always returns zero
+ 1
I edited my answer, read it again please :p
+ 1
The Code Project provided a code for that, but why's it always returning zero instead of the binary version
+ 1
As I said you’re returning num variable, and you should return binary variable
+ 1
Ok sorry I just saw that you had edited it. Alright I have done that but, String binary has already been defined in the method, that's the error message I am receiving now when I declare the String binary in the bracket as in toBinary(String binary)
+ 1
I have solved it thanks
+ 1
I should have maintained the int num in as in toBinary(int num).
So when I got that error message: String binary has already been defined
- I realized that, that I was doing the wrong thing by trying to pass the String binary as an argument. The goal is to pass the integer num instead
+ 1
;) congratz!!
0
Here is a solution using recursion:
https://code.sololearn.com/cxRQ7uWbNUom/?ref=app