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 )