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.
11 Answers
New AnswerYou 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 Bhardwaj11 Answers
New AnswerShivam 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);
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.
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.
I have been solved this problem for(int n = 1;n<=months;n++){ amount =amount-amount/10; if(n==3){ System.out.println(amount)
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message