83 lines
2.6 KiB
Java
83 lines
2.6 KiB
Java
import java.util.Arrays;
|
|
|
|
public class Testat1B {
|
|
|
|
public static int computeWithIf(int value) {
|
|
if (value == 1 || value == 2 || value == 4) {
|
|
return value;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static int computeWithSwitch(int value) {
|
|
// TODO: implement Aufgabe 1
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static void fillWithWhile(int[] array) {
|
|
int i = 0;
|
|
while (i < array.length) {
|
|
array[i] = i * 2;
|
|
i += 1;
|
|
}
|
|
}
|
|
|
|
public static void fillWithFor(int[] array) {
|
|
// TODO: implement Aufgabe 2
|
|
}
|
|
|
|
public static int maxArray(int[] array) {
|
|
// TODO: implement Aufgabe 3
|
|
return 0;
|
|
}
|
|
|
|
public static int[] sumColumns(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: " + computeWithSwitch(1));
|
|
System.out.println("Eingabewert: 2\tErwartete Ausgabe: 2\tIhre Ausgabe: " + computeWithSwitch(2));
|
|
System.out.println("Eingabewert: 3\tErwartete Ausgabe: 0\tIhre Ausgabe: " + computeWithSwitch(3));
|
|
System.out.println("Eingabewert: 4\tErwartete Ausgabe: 4\tIhre Ausgabe: " + computeWithSwitch(4));
|
|
System.out.println("Eingabewert: 5\tErwartete Ausgabe: 0\tIhre Ausgabe: " + computeWithSwitch(5));
|
|
System.out.println();
|
|
|
|
System.out.println("Aufgabe 2");
|
|
System.out.println("-----");
|
|
int[] array = new int[] {7, 2, 5};
|
|
fillWithFor(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};
|
|
fillWithFor(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, 9, 1};
|
|
System.out.println("Eingabearray: [5, 2, 4, 7, 9, 1]");
|
|
System.out.println("Erwartete Ausgabe: 9");
|
|
System.out.println("Ihre Ausgabe: " + maxArray(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[11, 17, 9]");
|
|
System.out.println("Ihre Ausgabe:\n" + Arrays.toString(sumColumns(array2)));
|
|
System.out.println();
|
|
}
|
|
}
|