-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2-9.txt
34 lines (31 loc) · 1.41 KB
/
D2-9.txt
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
class Acccount{
public static void main(String[] args){
double balance = 6000;
double rateOfInterest = 0.10;
double interest = 0;
double withdrawal = 500;
double deposit = 600;
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
for(int i: arr) { // The iteration in the loop happens automatically. The value is assigned to
//variable i from the array in every iteration of the loop.
balance += deposit; // Loop will repeat the statements in its body till the last element is reached in the array.
balance -= withdrawal;
interest = balance * rateOfInterest;
balance += interest;
System.out.println("The interest for the month " + i + " is " + interest);
}
}
}
Output:
The interest for the month 1 is 610.0
The interest for the month 2 is 681.0
The interest for the month 3 is 759.1
The interest for the month 4 is 845.0100000000001
The interest for the month 5 is 939.5110000000001
The interest for the month 6 is 1043.4621000000002
The interest for the month 7 is 1157.8083100000001
The interest for the month 8 is 1283.5891410000004
The interest for the month 9 is 1421.9480551000004
The interest for the month 10 is 1574.1428606100003
The interest for the month 11 is 1741.5571466710005
The interest for the month 12 is 1925.7128613381003