0
Need java Code
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
4 ответов
+ 1
Show your attempt Qudrat Jan buddy =D So that we can correct you
+ 1
At line
>>> remainingAmount = amountBorrowed - returnedPerMonth;
It will be
>>> remainingAmount = amountBorrowed - amountBorrowed * 0.1;
Reason:
Each month the returnPerMonth is added but we need to subtract only the amount paid in that month.
0
import java.util.*;
public class Program{
public static void main(String []args){
int TOTAL_MONTHS = 3;
Scanner input = new Scanner(System.in);
System.out.print("Enter amount borrowed: ");
double amountBorrowed = input.nextDouble();
double remainingAmount = 0;
double returnedPerMonth = 0;
while (TOTAL_MONTHS != 0) {
returnedPerMonth = amountBorrowed * 0.1;
remainingAmount = amountBorrowed - returnedPerMonth;
amountBorrowed -= returnedPerMonth;
TOTAL_MONTHS--;
System.out.println("The remaining amount is: " + remainingAmount);
}
}
}
0
Thnx!