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)); } }

27th Jul 2022, 9:50 PM
MR KINGSHOW
MR KINGSHOW - avatar
5 Answers
+ 1
Why did you change the code that was provided to you and what do you think it is? 😳 int x == int y;
28th Jul 2022, 12:40 AM
Solo
Solo - avatar
+ 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..
28th Jul 2022, 8:49 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 please can you help me with the correct answer
21st Aug 2022, 11:25 AM
MR KINGSHOW
MR KINGSHOW - avatar
0
Why don't you try the mentioned changes?
21st Aug 2022, 11:47 AM
Jayakrishna 🇮🇳
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.
21st Aug 2022, 11:47 AM
Jayakrishna 🇮🇳