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.
1 Antwort
0
Thank you Mirielle! 😁👍