In this following i have been already solved but it show three all three results but i need only last one so help me someone. | Sololearn: Learn to code for FREE!

0

In this following i have been already solved but it show three all three results but i need only last one so help me someone.

You take a loan from a friend and need to calculate how much you will owe him after 3 months. You are going to pay him back 10% of the remaining loan amount each month. Create a program that takes the loan amount as input, calculates and outputs the remaining amount after 3 months. Sample Input: 20000 Sample Output: 10628 Here is the monthly payment schedule: Month 1 Payment: 10% of 20000 = 2000 Remaining amount: 18000 Month 2 Payment: 10% of 18000 = 1800 Remaining amount: 16200 Month 3: Payment: 10% of 16200 = 1620 Remaining amount: 14580 ***** My program is int months=3; for(int n = 1;n<=months;n++){ amount =amount-amount/10; System.out.println(amount );

5/18/2022 1:51:08 AM

Shivam Bhardwaj

11 Answers

New Answer

+1

Shivam Bhardwaj amount = amount - amount * 10 / 100; or amount = amount * 90 / 100;

+1

Shivam Bhardwaj Try this again Scanner sc = new Scanner(System.in); int amount = sc.nextInt(); for (int i = 0; i < 3; i++) { amount = amount - amount * 10 / 100; } System.out.print(amount);

+1

Shivam Bhardwaj I am getting all right output.

+1

Thanks for help

0

Again result is same because your formulas is short format of my formula but problem is not there.Problem is 3 output results those are right. but I need only last one.

0

I try it 1 min ago

0

Please give me your WhatsApp number and I share some screenshots with you sir

0

Then you find my mistake easyly

0

Shivam Bhardwaj If amount is being re-assigned each iteration, then you don't need to print the amount each time. Print amount when the loop has finished, then you will get a single output as required.

0

How ? Please discribe.

0

I have been solved this problem for(int n = 1;n<=months;n++){ amount =amount-amount/10; if(n==3){ System.out.println(amount)