-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExercise.java
More file actions
36 lines (29 loc) · 944 Bytes
/
Exercise.java
File metadata and controls
36 lines (29 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int k;
float p;
int n;
boolean loop;
do {
System.out.print("Gib bitte das Startkapital ein (in Euro): ");
k = scanner.nextInt();
System.out.print("Gib bitte den Prozentsatz ein: ");
p = scanner.nextFloat();
System.out.print("Gib bitte die Anzahl Jahre ein: ");
n = scanner.nextInt();
System.out.println(
"Ergebnis: Das Endkapital betraegt " + (int) calculateInterest(k, p, n) + " Euro");
System.out.print("Willst Du eine weitere Zinsrechnung durchfuehren (true, false)?: ");
loop = scanner.nextBoolean();
} while (loop);
scanner.close();
}
static double calculateInterest(int k, float p, int n) {
if (n == 0) {
return k;
}
return calculateInterest(k, p, n - 1) * (1 + p / 100);
}
}