Computer Science, asked by nidhijha53, 7 months ago

Mr Agarwal invest certain sum at 5% per annum compound interest for 3 years. write a program in Java to calculate and display :
a) the interest for the first year
b) the interest for the second year
c) the interest for the third year
Take sum as an input from the user
Sample input : principal =rupees 5000
Sample output : interest for the first year :rupees 500
Interest for the second year 550
Interest for the third year :rupees 605​

Answers

Answered by zack1706
37

Explanation:

Mr. Agarwal invests certain sum at 5% per annum

* compound interest for three years. Write a program in Java to calculate:

* (a) the interest for the first year

* (b) the interest for the second year

* (c) the amount after three years

* Take sum as an input from the user.

*/

import java.util.*;

class V1 {

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Enter the Principle:");

double p = in.nextDouble();

double i,a;

i=(p*5)/100.0;

a=p+i;

p=a;

System.out.println("Interest after First Year: "+i);

i=(p*5)/100.0;

a=p+i;

p=a;

System.out.println("Interest after Second Year: "+i);

a=p+(p*5)/100.0;

System.out.println("Amount after Third Year: "+a);

}

}

Answered by Kezukirihara
3

Answer:

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter sum of money: ");

double p = in.nextDouble();

double interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the first year = " + interest);

p += interest;

interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the second year = " + interest);

p += interest;

interest = p * 5 * 1 / 100.0;

System.out.println("Interest for the third year = " + interest);

}

}

Similar questions