Convertidor binario (error) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Convertidor binario (error)

Tengo una duda, lo que pasa es que yo estoy haciendo el desafio de convertidor un numero en codigo binario y pues me sale todo bueno menos el caso 4, ¿Alguien me podria decir donde esta mi error? Se lo agradecería un monton 🙌 import java.util.Scanner; //tu código va aquí public class Converter{ public static int toBinary(int num){ String binary = ""; String x = ""; int w = 0; int l = num; while(num > 0) { w = num%2; x = String.valueOf(w); binary = x+binary; num /= 2; } if (l == 0){ return 0; } else{ int resultado = Integer.parseInt(binary); return resultado; } } } 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)); } }

19th Dec 2020, 4:27 AM
Matías Aguirre
Matías Aguirre - avatar
5 Antworten
0
Try Englisch
25th Dec 2020, 12:58 PM
Julian Bents
Julian Bents - avatar
0
Por si ha alguien le Interesa Mi Codigo xd es Muy Resumido : import java.util.Scanner; public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); //Mi Codigo va Aqui System.out.print(Integer.toBinaryString(x)); } }
12th Oct 2021, 9:50 PM
Jhon Stiven Caicedo Mosquera
Jhon Stiven Caicedo Mosquera - avatar
0
Con este código no te da errores //tu código va aquí Public class Converter { Public static String toBinary(int num){ String binary = ""; while(num>0){ binary = (num%2)+binary; num=num/2; } return binary; } }
7th Oct 2022, 3:11 AM
Elías Diego Gomez
Elías Diego Gomez - avatar
- 1
import java.util.Scanner; 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)); } }
21st Apr 2021, 2:38 AM
Jose Reinaldo Parra Morales
Jose Reinaldo Parra Morales - avatar
- 2
Estas utilizando mas variables de las que necesitas, prueba así: public class Converter { public static String toBinary(int x){ String binary=""; while (x>0){ binary = (x%2)+binary; x/=2; } return binary; } }
14th Apr 2021, 9:39 AM
James Ruiz
James Ruiz - avatar