Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"image": "mcr.microsoft.com/devcontainers/java:21"
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"vscjava.vscode-java-pack"
]
}
34 changes: 32 additions & 2 deletions Exercise.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
public class Exercise {
import java.util.Scanner;

public class Exercise {
public static void main(String[] args) {
// implement exercise here
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);
}
}
Loading