VL-Programmieren/VL04/Aufgabe05/Aufgabe05.java

55 lines
1.3 KiB
Java
Raw Normal View History

2024-05-13 14:04:41 +00:00
package VL04.Aufgabe05;
/**
* Vorlesung 4 / Aufgabe 5
*
* @author Sebastian Brosch
*/
public class Aufgabe05 {
public static void main(String[] args) {
final int DIR_LEFT = 0;
final int DIR_RIGHT = 1;
final int NUM_FROGS = 100;
int[] numbersrow = new int[1000];
2024-05-16 08:50:07 +00:00
int[] bucket = new int[] { 0, 0 };
2024-05-13 14:04:41 +00:00
int position = 1;
int position_max = position;
for (int i = 0; i < numbersrow.length; i++) {
numbersrow[i] = DIR_RIGHT;
}
for (int f = NUM_FROGS; f > 0; f--) {
position = 1;
while (position > 0) {
numbersrow[position] = (numbersrow[position] == DIR_RIGHT) ? DIR_LEFT : DIR_RIGHT;
if (numbersrow[position] == DIR_RIGHT) {
position++;
if (position_max < position) {
position_max = position;
}
} else {
switch (position) {
case 1:
bucket[0]++;
break;
case 2:
bucket[1]++;
break;
}
position -= 2;
}
}
}
System.out.printf("Linker Eimer: %d Frösche\n", bucket[0]);
System.out.printf("Rechter Eimer: %d Frösche\n", bucket[1]);
System.out.printf("Maximale Position auf der Zahlengerade: %d\n", position_max);
}
}