0
Binary converter
it does not work why https://code.sololearn.com/c4CbZEi2Ty1g/?ref=app
7 odpowiedzi
+ 1
it works thank you so much
+ 1
Martin Taylor thank you so the calculation method is not necessary
+ 1
import java.util.Scanner;
//your code goes here
public class Converter {
public static String toBinary(int num){
String binary="";
while(num > 0) {
binary = (num%2)+binary;
num /= 2;
}
return binary;
}
}
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));
}
}
0
You are return value of num which is 0 at end. But you need to return binary which is calculated..
so use.
return binary;
Instead of return Integer.toBinaryString(num);
0
thank you
0
You're welcome..