86 lines
2.5 KiB
Java
86 lines
2.5 KiB
Java
import java.util.Arrays;
|
|
|
|
public class Testat1A {
|
|
|
|
public static int computeWithSwitch(int value) {
|
|
switch (value) {
|
|
case 1:
|
|
case 2:
|
|
case 4:
|
|
return value;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static int computeWithIf(int value) {
|
|
// TODO: implement Aufgabe 1
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static void fillWithFor(int[] array) {
|
|
for (int i = 0; i < array.length; i++) {
|
|
array[i] = i * 2;
|
|
}
|
|
}
|
|
|
|
public static void fillWithWhile(int[] array) {
|
|
// TODO: implement Aufgabe 2
|
|
}
|
|
|
|
public static int minArray(int[] array) {
|
|
// TODO: implement Aufgabe 3
|
|
return 0;
|
|
}
|
|
|
|
public static int[] sumRows(int[][] array) {
|
|
// TODO: implement Aufgabe 4
|
|
return new int[0];
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println("Aufgabe 1");
|
|
System.out.println("-----");
|
|
System.out.println("Eingabewert: 1\tErwartete Ausgabe: 1\tIhre Ausgabe: " + computeWithIf(1));
|
|
System.out.println("Eingabewert: 2\tErwartete Ausgabe: 2\tIhre Ausgabe: " + computeWithIf(2));
|
|
System.out.println("Eingabewert: 3\tErwartete Ausgabe: 0\tIhre Ausgabe: " + computeWithIf(3));
|
|
System.out.println("Eingabewert: 4\tErwartete Ausgabe: 4\tIhre Ausgabe: " + computeWithIf(4));
|
|
System.out.println("Eingabewert: 5\tErwartete Ausgabe: 0\tIhre Ausgabe: " + computeWithIf(5));
|
|
System.out.println();
|
|
|
|
System.out.println("Aufgabe 2");
|
|
System.out.println("-----");
|
|
int[] array = new int[] {7, 2, 5};
|
|
fillWithWhile(array);
|
|
System.out.println("Eingabearray: [7, 2, 5]");
|
|
System.out.println("Erwartete Ausgabe: [0, 2, 4]");
|
|
System.out.println("Ihre Ausgabe: " + Arrays.toString(array));
|
|
System.out.println();
|
|
array = new int[] {9, 1, 0, 7, 9};
|
|
fillWithWhile(array);
|
|
System.out.println("Eingabearray: [9, 1, 0, 7, 9]");
|
|
System.out.println("Erwartete Ausgabe: [0, 2, 4, 6, 8]");
|
|
System.out.println("Ihre Ausgabe: " + Arrays.toString(array));
|
|
System.out.println();
|
|
|
|
System.out.println("Aufgabe 3");
|
|
System.out.println("-----");
|
|
array = new int[] {5, 2, 4, 7, 1, 9};
|
|
System.out.println("Eingabearray: [5, 2, 4, 7, 1, 9]");
|
|
System.out.println("Erwartete Ausgabe: 1");
|
|
System.out.println("Ihre Ausgabe: " + minArray(array));
|
|
System.out.println();
|
|
|
|
System.out.println("Aufgabe 4");
|
|
System.out.println("-----");
|
|
int[][] array2 = new int[][] { {5, 2, 4}, {7, 1, 9}, {3, 0, 6}};
|
|
System.out.println("Eingabearray:\n[5, 7, 3]\n[2, 1, 0]\n[4, 9, 6]");
|
|
System.out.println("Erwartete Ausgabe:\n[15, 3, 19]");
|
|
System.out.println("Ihre Ausgabe:\n" + Arrays.toString(sumRows(array2)));
|
|
System.out.println();
|
|
}
|
|
|
|
}
|