18 lines
496 B
Java
18 lines
496 B
Java
public class IntToBinary {
|
|
// !!!!! DER REST DER AUFGABE IST IN DER README.md BEANTWORTED !!!!!
|
|
// BITTE Main.java MIT BEACHTEN
|
|
// BITTE Main.java MIT BEACHTEN !!!!!!!!!!
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|