+ 1

Java : Code Project (Loan Calculator)

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. I want to know if I did this the right way because it felt like I was doing it wrong in a way. Can someone please assist me. Here is my code : edited: int amount = scanner.nextInt(); for (int month = 1; month <= 3; month++){ //month 1 int remainderMonth1 = (int) (amount * 0.1);//2000 int remainder1 = (int) (amount - remainderMonth1); //18 000 //month 2 int remainderMonth2 = (int) (remainder1 * 0.1); //1800 int remainder2 = (int) (remainder1 - remainderMonth2); //16200 //month 3 int remainderMonth3 = (int) (remainder2 * 0.1); int remainder3 = (int) (remainder2 - remainderMonth3); System.out.println(remainder3); break; } I didnt add the input here but ( Amount is the input )

12th Oct 2021, 12:54 PM
Edward Marais
Edward Marais - avatar
1 Answer
+ 5
You have coded that what the loop should do. In the example I present another way, you can follow for the variable „amount2“: https://code.sololearn.com/cwX6BldKpN8L/?ref=app
12th Oct 2021, 1:31 PM
JaScript
JaScript - avatar