Skip to content

Commit f40374d

Browse files
committed
Implement Solution
1 parent 0fced0c commit f40374d

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Exercise.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1-
public class Exercise {
1+
import java.util.Scanner;
22

3+
public class Exercise {
34
public static void main(String[] args) {
4-
// implement exercise here
5+
Scanner scanner = new Scanner(System.in);
6+
int k;
7+
float p;
8+
int n;
9+
10+
boolean loop;
11+
do {
12+
System.out.print("Gib bitte das Startkapital ein (in Euro): ");
13+
k = scanner.nextInt();
14+
15+
System.out.print("Gib bitte den Prozentsatz ein: ");
16+
p = scanner.nextFloat();
17+
18+
System.out.print("Gib bitte die Anzahl Jahre ein: ");
19+
n = scanner.nextInt();
20+
21+
System.out.println(
22+
"Ergebnis: Das Endkapital betraegt " + (int) calculateInterest(k, p, n) + " Euro");
23+
24+
System.out.print("Willst Du eine weitere Zinsrechnung durchfuehren (true, false)?: ");
25+
loop = scanner.nextBoolean();
26+
} while (loop);
27+
scanner.close();
28+
}
29+
30+
static double calculateInterest(int k, float p, int n) {
31+
if (n == 0) {
32+
return k;
33+
}
34+
return calculateInterest(k, p, n - 1) * (1 + p / 100);
535
}
636
}

0 commit comments

Comments
 (0)