Computer Science, asked by HarshSingh0123, 8 months ago

The simple interest (SI) and compound interest (CI) of a sum for a given time (T) and rate (R) can be calculated as :
(a) SI = (p*r*t)/100
(b) CI = p*((1+(r/100))T-1)
Write a JAVA program to input sum , rate , time and type of Interest ('S' for Simple Interest and 'C' for Compound Interest ) . Calculate and display the sum and the interest earned .

Answers

Answered by anindyaadhikari13
10

Answer:-

First of all, we have to know the formula.

 \sf SI =  \frac{p \times r \times t}{100}

And,

\sf  CI =P \{(1+\frac{R}{100})^{T} - 1 \}

Now, we will solve the program.

import java.util.*;

class Interest

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter principal amount: ");

double p=sc.nextDouble();

System.out.print("Enter rate of interest: ");

double r=sc.nextDouble();

System.out.print("Enter time: ");

double t=sc.nextDouble();

System.out.println("Enter C for calculating compound interest and S for calculating Simple Interest. ");

char ch=sc.next().charAt(0);

if(ch=='C' || ch=='c')

{

double CI=p*(Math.pow((1+r/100.0),t)-1);

System.out.println("Compound Interest is: "+CI);

}

else if(ch=='s'|| ch=='S')

{

double SI=p*r*t/100.0;

System.out.println("Simple Interest is: "+SI);

}

else

System.out.println("Invalid Choice. ");

}

}

Answered by Kaptivate
6

Answer:

import java.util.*;

class Interest {  

public static void main(String s[])  

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter principal amount: ");

double p=sc.nextDouble();

System.out.print("Enter rate of interest: ");

double r=sc.nextDouble();

System.out.print("Enter time: ");

double t=sc.nextDouble();

System.out.println("Enter C for calculating compound interest and S for calculating Simple Interest. ");

char ch=sc.next().charAt(0);

if(ch=='C' || ch=='c')

{

double CI=p*(Math.pow((1+r/100.0),t)-1);

System.out.println("Compound Interest is: "+CI);

}

else if(ch=='s'|| ch=='S')

{

double SI=p*r*t/100.0;

System.out.println("Simple Interest is: "+SI);

}

else

System.out.println("Invalid Choice. ");  

}}

Explanation:

Even I had this question but from the book reference, I did it and it did come for me.

Similar questions