Hausaufgabe-10-11/IntToBinary.java
Sobottasgithub b8ea28c915 Init
2025-11-12 11:45:31 +01:00

16 lines
417 B
Java

public class IntToBinary {
// !!!!! DER REST DER AUFGABE IST IN DER README.md BEANTWORTED !!!!!
public int binary(int n) {
if (n < 0) {
// Invalid input
return -1;
} else if (n <= 1) {
return n;
} else {
// Prevent adding the numbers by converting to String and convert it back to int after
return Integer.parseInt(Integer.toString(binary(n/2)) + (n%2));
}
}
}