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 );

18th May 2022, 1:51 AM
Shivam Bhardwaj
11 Answers
+ 1
Shivam Bhardwaj amount = amount - amount * 10 / 100; or amount = amount * 90 / 100;
18th May 2022, 2:54 AM
A͢J
A͢J - avatar
+ 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);
18th May 2022, 3:20 AM
A͢J
A͢J - avatar
+ 1
Shivam Bhardwaj I am getting all right output.
18th May 2022, 3:22 AM
A͢J
A͢J - avatar
+ 1
Thanks for help
18th May 2022, 3:34 AM
Shivam Bhardwaj
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.
18th May 2022, 3:11 AM
Shivam Bhardwaj
0
I try it 1 min ago
18th May 2022, 3:22 AM
Shivam Bhardwaj
0
Please give me your WhatsApp number and I share some screenshots with you sir
18th May 2022, 3:31 AM
Shivam Bhardwaj
0
Then you find my mistake easyly
18th May 2022, 3:33 AM
Shivam Bhardwaj
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.
18th May 2022, 4:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
How ? Please discribe.
18th May 2022, 1:38 PM
Shivam Bhardwaj
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)
18th May 2022, 3:23 PM
Shivam Bhardwaj