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)); } }
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));
}
}
+ 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
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
0
Here you go..
https://code.sololearn.com/c4Q8DGPjMc5m/?ref=app