File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed
Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments