0
Convertidor Binario
No.puedo resolver el código ayuda 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)); }
3 Antworten
+ 2
Attempt?
0
You wrote `Class` for defining the `Converter` class, it should be `class` not `Class`
public class Converter // public Class Converter
Class `Program` is missing a closing curly bracket of its body.
0
import java.util.Scanner;
public class Converter
{
static String toBinary(int num){
String binary="";
while(num > 0) {
binary = (num%2)+binary;
num /= 2;
}
return binary;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.print(Converter.toBinary(x));
}
}