0

Can you rectify my mistake for Binary Code Challenge (in Java)?

https://code.sololearn.com/cMf5qfGzfBNJ/?ref=app The binary numeric system uses only two digits: 0 and 1. Computers operate in binary, meaning they store data and perform calculations using only zeros and ones. You need to make a program to convert integer numbers to their binary representation. Create a Converter class with a static toBinary() method, which returns the binary version of its argument. The code in main takes a number as input and calls the corresponding static method. Make sure the code works as expected. Sample Input: 42 Sample Output: 101010 You can use the following code to convert a number to binary: String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; }

8th Dec 2020, 9:21 AM
Ray
Ray - avatar
6 odpowiedzi
- 7
Rabeeh add data type to return before the method name.
8th Dec 2020, 10:28 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Return binary instead of num, and add the return type to the method.
8th Dec 2020, 9:43 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
How to add return type in method? CarrieForle
8th Dec 2020, 10:11 AM
Ray
Ray - avatar
0
CarrieForle thanks mate :)
8th Dec 2020, 10:52 AM
Ray
Ray - avatar
0
9th Dec 2021, 9:00 PM
sahand dara hwsin