+ 2
How to fix error "void type not allowed here" in java
import java.util.Scanner; //введите код сюда public class Converter{ public static void toBinary(int x) { String binary = ""; while (x > 2 ){ binary = (x%2) + binary; x /= 2; } } } 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
+ 3
Your toBinary() method is void type but you expecting to print returned value in
System.out.println( Convertor.toBinary(x)) ; // since called method is void, does not return anything...
Either return value or just call method without print statement...
+ 2
thx
+ 1
edit: you're welcome.
+ 1
Make your toBinary method return type string and return binary string.