0

Can anyone please help me with this code please,

import java.util.Scanner; public class Program { public static void main(String[ ] args) {Scanner scanner = new Scanner(System.in); int initialAmount = scanner.nextInt(); for(int month = 1;month <= 3; month++) {int payment = (10 * initialAmount) / 100; int remainingAmount = initialAmount - payment; System.out.println(remainingAmount);}; } }

14th Jan 2022, 10:23 PM
Giddy Da-huncho🙃😇💓
Giddy Da-huncho🙃😇💓 - avatar
4 Réponses
+ 4
In the loop, payment and remainingAmount are being calculated from initialAmount every time so they calculate the same numbers no matter how many times the loop repeats. To fix this, declare remainingAmount before the loop and assign it to initialAmount. Now inside the loop replace initialAmount with remainingAmount in your calculations. Finally, move the println out of the loop and print only once, after the loop has completed.
14th Jan 2022, 11:00 PM
Brian
Brian - avatar
+ 1
Thanks brian
14th Jan 2022, 11:01 PM
Giddy Da-huncho🙃😇💓
Giddy Da-huncho🙃😇💓 - avatar
0
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
14th Jan 2022, 10:30 PM
Giddy Da-huncho🙃😇💓
Giddy Da-huncho🙃😇💓 - avatar
0
Please any help
14th Jan 2022, 10:30 PM
Giddy Da-huncho🙃😇💓
Giddy Da-huncho🙃😇💓 - avatar