112 lines
3.2 KiB
Java
112 lines
3.2 KiB
Java
package Semester1;
|
|
|
|
public class Aufgabe4 {
|
|
public static void main(String[] args) {
|
|
System.out.println("\n\n Script Teil 4: ");
|
|
//Aufgabe1
|
|
final int MAXIMUM = 5;
|
|
for (int i = 1; i < MAXIMUM; i++) {
|
|
if (i % 2 == 0) {
|
|
System.out.println(i);
|
|
}
|
|
}
|
|
for (int i = MAXIMUM; i > 0; i--) {
|
|
if (i % 2 != 0) {
|
|
System.out.println(i);
|
|
}
|
|
}
|
|
//Aufgabe2
|
|
int loesung = 0;
|
|
for (int i = 1; i<=20; i++) {
|
|
loesung += i;
|
|
System.out.println(loesung);
|
|
}
|
|
loesung = 0;
|
|
int zaeler = 0;
|
|
while (zaeler <= 20) {
|
|
loesung += zaeler;
|
|
zaeler++;
|
|
System.out.println(loesung);
|
|
}
|
|
loesung = 0;
|
|
zaeler = 0;
|
|
do {
|
|
loesung += zaeler;
|
|
zaeler++;
|
|
System.out.println(loesung);
|
|
} while (zaeler <= 20);
|
|
|
|
//Uebungsaufgaben.Aufgabe3
|
|
int s = 100;
|
|
boolean[] zahlen = new boolean [s+1];
|
|
for (int i = 0; i <= s; i++) {
|
|
zahlen[i] = true;
|
|
}
|
|
int basis = 0;
|
|
|
|
for (int i = 2; i <= s/2; i++) {
|
|
if (zahlen[i]) {
|
|
basis = i;
|
|
for (int x = i + basis; x <= s; x += basis) {
|
|
zahlen[x] = false;
|
|
}
|
|
}
|
|
}
|
|
for (int i = 1; i <= s; i++) {
|
|
if (zahlen[i]) {
|
|
System.out.println(i);
|
|
}
|
|
}
|
|
//Aufgabe4
|
|
float kapital = 200.80f;
|
|
int laufzeit = 50;
|
|
float zins1 = 0.03f;
|
|
float zins2 = 0.031f;
|
|
float zins3 = 0.032f;
|
|
|
|
for (int i = 0; i <= laufzeit; i++) {
|
|
System.out.println(kapital*Math.pow(1+zins1, i));
|
|
System.out.println(kapital*Math.pow(1+zins2, i));
|
|
System.out.println(kapital*Math.pow(1+zins3, i));
|
|
System.out.println("\n");
|
|
}
|
|
|
|
|
|
//Aufgabe5
|
|
int froesche = 1000;
|
|
int eimer0 = 0;
|
|
int eimer1 = 0;
|
|
int posfrosch = 2;
|
|
boolean[] felder = new boolean [froesche+1];
|
|
for (int i = 0; i <= froesche; i++) {
|
|
felder[i] = true;
|
|
}
|
|
while (eimer1 + eimer0 < froesche) {
|
|
if (posfrosch == 0) {
|
|
eimer1++;
|
|
posfrosch = 2;
|
|
System.out.println("\n Neuer Frosch bei -1");
|
|
} else if (posfrosch == 1) {
|
|
eimer0++;
|
|
posfrosch = 2;
|
|
System.out.println("\n Neuer Frosch bei 0");
|
|
}
|
|
felder[posfrosch] = !felder[posfrosch];
|
|
if (felder[posfrosch]) {
|
|
posfrosch ++;
|
|
System.out.println("Frosch nach 1 rechts");
|
|
} else {
|
|
posfrosch -= 2;
|
|
System.out.println("Frosch nach 2 links");
|
|
}
|
|
}
|
|
System.out.println("Eimer 0 beinhaltet " + eimer0 + " Frösche");
|
|
System.out.println("Eimer -1 beinhaltet " + eimer1 + " Frösche");
|
|
|
|
//Aufgabe6
|
|
enum Monat {
|
|
JANUAR, FEBRUAR, MÄRZ, APRIL, MAI, JUNI, JULI, AUGUST, SEPTEMBER, OKTOBER, NOVEMBER, DEZEMBER
|
|
}
|
|
}
|
|
}
|