0
What's my error please un this binary converter
import java.util.Scanner; //your code goes here public class Converter{ static int toBinary (){ String binary=""; int num; while (y>0){ binary = (y%2)+binary; y/=2; return num; } } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int x == int y; System.out.print(Converter.toBinary(x)); } }
5 Réponses
+ 1
Why did you change the code that was provided to you and what do you think it is? 😳
int x == int y;
+ 1
You are passing value x but there is no method to accepting it.. 
Use
toBinary( int y) {
return should be after loop.. 
return binary by converting to int type. 
Else make return type string and return 'binary' string.. 
Hope it helps..
0
Jayakrishna🇮🇳 please can you help me with the correct answer
0
Why don't you try the mentioned changes?
0
Corrected method:
static int toBinary (int y){
    String binary="";
    while (y>0){
        binary = (y%2)+binary;
        y/=2;
     }
          
return Integer.parseInt(binary);
}
        // int x == int y; remove it.



