0

Binary Converter

This is the code for a project that I'm doing: import java.util.Scanner; //your code goes here class Converter { static int toBinary(int num) { String binary=""; while(num > 0) { binary = (num%2)+binary; num /= 2; } return num; } } 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)); } } What is wrong with my code? It should return a binary value whenever a user is trying to enter an integer. Instead, it is returning zero.

24th Jan 2023, 8:41 PM
Gradi Maxime Kasita Mbatika
1 Antwort
0
Thank you Mirielle! 😁👍
24th Jan 2023, 9:30 PM
Gradi Maxime Kasita Mbatika