Fixup
This commit is contained in:
parent
7512346c7a
commit
52b14b6ad2
@ -7,22 +7,22 @@ public class HandleArray {
|
|||||||
if (arrayInput.length > 1) {
|
if (arrayInput.length > 1) {
|
||||||
printArray(Arrays.copyOfRange(arrayInput, 1, arrayInput.length));
|
printArray(Arrays.copyOfRange(arrayInput, 1, arrayInput.length));
|
||||||
} else {
|
} else {
|
||||||
System.out.print("\n");
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printArrayRev(int[] arrayInput) {
|
public void printArrayRev(int[] arrayInput) {
|
||||||
System.out.print(arrayInput[arrayInput.length-1] + " ");
|
System.out.print(arrayInput[arrayInput.length - 1] + " ");
|
||||||
if (arrayInput.length > 1) {
|
if (arrayInput.length > 1) {
|
||||||
printArrayRev(Arrays.copyOfRange(arrayInput, 0, arrayInput.length-1));
|
printArrayRev(Arrays.copyOfRange(arrayInput, 0, arrayInput.length - 1));
|
||||||
} else {
|
} else {
|
||||||
System.out.print("\n");
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sumRec(int[] arrayInput) {
|
public int sumRec(int[] arrayInput) {
|
||||||
// WIRD AUSGEGEBEN IN DER Main.java
|
// WIRD AUSGEGEBEN IN DER Main.java
|
||||||
if(arrayInput.length > 0) {
|
if (arrayInput.length > 0) {
|
||||||
return arrayInput[0] + sumRec(Arrays.copyOfRange(arrayInput, 1, arrayInput.length));
|
return arrayInput[0] + sumRec(Arrays.copyOfRange(arrayInput, 1, arrayInput.length));
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
public class IntToBinary {
|
public class IntToBinary {
|
||||||
// !!!!! DER REST DER AUFGABE IST IN DER README.md BEANTWORTED !!!!!
|
// !!!!! DER REST DER AUFGABE IST IN DER README.md BEANTWORTED !!!!!
|
||||||
// BITTE Main.java MIT BEACHTEN !!!!!!!!!!
|
// BITTE Main.java MIT BEACHTEN !!!!!!!!!!
|
||||||
|
|
||||||
public String binary(int n) {
|
public String binary(int n) {
|
||||||
if (n <= 1) {
|
if (n <= 1) {
|
||||||
return "" + n;
|
return "" + n;
|
||||||
} else {
|
} else {
|
||||||
// Prevent adding the numbers by converting to String and convert it back to int after
|
// Prevent adding the numbers by converting to String and convert it back to int after
|
||||||
return binary(n/2) + (n%2);
|
return binary(n / 2) + (n % 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
Main.java
40
Main.java
@ -1,27 +1,27 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
// !!!!!DER REST DER AUFGABE IST IN DER README.md BEANTWORTET!!!!!
|
// !!!!!DER REST DER AUFGABE IST IN DER README.md BEANTWORTET!!!!!
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// exercise 1
|
// exercise 1
|
||||||
System.out.println("Aufgabe 1");
|
System.out.println("Aufgabe 1");
|
||||||
IntToBinary intToBinary = new IntToBinary();
|
IntToBinary intToBinary = new IntToBinary();
|
||||||
|
|
||||||
System.out.println(intToBinary.binary(3));
|
System.out.println(intToBinary.binary(3));
|
||||||
System.out.println(intToBinary.binary(6));
|
System.out.println(intToBinary.binary(6));
|
||||||
System.out.println(intToBinary.binary(9));
|
System.out.println(intToBinary.binary(9));
|
||||||
|
|
||||||
// exercise 2
|
// exercise 2
|
||||||
System.out.println("Aufgabe 2");
|
System.out.println("Aufgabe 2");
|
||||||
int[] array = {15,3,22,43};
|
int[] array = {15, 3, 22, 43};
|
||||||
HandleArray handleArray = new HandleArray();
|
HandleArray handleArray = new HandleArray();
|
||||||
|
|
||||||
handleArray.printArray(array);
|
handleArray.printArray(array);
|
||||||
|
|
||||||
// exercise 3
|
// exercise 3
|
||||||
System.out.println("Aufgabe 3");
|
System.out.println("Aufgabe 3");
|
||||||
handleArray.printArrayRev(array);
|
handleArray.printArrayRev(array);
|
||||||
|
|
||||||
// exercise 4
|
// exercise 4
|
||||||
System.out.println("Aufgabe 4");
|
System.out.println("Aufgabe 4");
|
||||||
System.out.println(handleArray.sumRec(array));
|
System.out.println(handleArray.sumRec(array));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user