Page 138 - CA_Blue( J )_Class10
P. 138
Program 4 To calculate the Simple Interest or Compound Interest depending on the user's choice. The principal
amount, rate of interest and time are to be accepted from the user.
t
[SI = prt/100 and CI = A = p(1+r/100) are the formulas of Simple Interest and Compound Interest]
1 import java.util.*;
2 class simple_compound_interest
3 {
4 public static void main()
5 {
6 Scanner sc=new Scanner(System.in);
7 double si,a,r,t,p,ci;
8 int ch;
9 System.out.print("Enter principal amount : ");
10 p=sc.nextDouble();
11 System.out.print("Enter rate : ");
12 r=sc.nextDouble();
13 System.out.print("Enter time : ");
14 t=sc.nextDouble();
15 System.out.print("Enter 1 for Simple Interest/ 2 for Compound
Interest : ");
16
17 switch(ch)
18 {
19 case 1 : si=(p*r*t)/100.0;
20 System.out.println("Simple Interest : "+si);
21 break;
22
23 case 2 : a = p * Math.pow((1 + (r/100.0)),t);
ci = a - p;
24 System.out.println("Compound Interest : "+ci);
25 break;
26
27 default: System.out.println("Wrong Choice");
28 }
29 }
30 }
136136 Touchpad Computer Applications-X

