0

Where is error occured?

import java.util.Scanner; public class converter{ public static void toBinary(){ int x = 0; } public static int toBinary (int x){ String binary =""; while(x>0){ binary = x%2 + binary; x /=2; } } } //your code goes here public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.print(Converter.toBinary(x)); } }

14th Sep 2021, 6:20 AM
Amala Yakin
4 Answers
+ 1
Amala Yakin 1 - Class name should start from Capital letter 2 - change return type to String and return binary in that method 3 - remove first unused method. 4 - remove previous question https://www.sololearn.com/Discuss/2881682/?ref=app ------ //Where is error occured? import java.util.Scanner; public class Converter { public static String toBinary (int x) { String binary = ""; while(x > 0) { binary = x % 2 + binary; x /= 2; } return binary; } } //your code goes here public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.print(Converter.toBinary(x)); } }
14th Sep 2021, 8:48 AM
A͢J
A͢J - avatar
+ 1
- class name is converter lowercase but you use it with uppercase -in second method is return type int declared, but method has no return statement
14th Sep 2021, 6:36 AM
zemiak
0
I believe there is an extra curly brace } after the clsing of defining the public class converter. Look and keep track of the opening and closing and I believe there is one with no beginning, hence useless. Delete that
14th Sep 2021, 6:24 AM
Kamil Hamid
Kamil Hamid - avatar
14th Sep 2021, 6:29 AM
Rupali Haldiya
Rupali Haldiya - avatar