0
[âď¸]Can anyone explain me answer of this problem (PS: see the Description ) ? I will upload my code in the answer section.
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
2 Answers
+ 3
why ? "amount = amount * 90 / 100;" ?
Because it is asked to discount 10%, so 90% is the remaining amount. So instead of subtracting 10% , directly finding 90%.
Why?
Instead of amount -= (amount /100) *10;
It makes difference in fraction parts and also if amount is less than 100, then amt/100 return 0 so total discount is 0
You can try,
amount -= (amount*10/100) ;
It works...
Hope it helps..
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
for ( int i = 0; i<3; i++)
{
// amount = amount - amount * 90 / 100;
amount = amount * 90 / 100;
// amount = amount /100 *10;
}
System.out.println(amount);
}
}
========================
//So my question is why the answer of this problem is "amount = amount * 90 / 100;" this statement ? Instead of amount -= (amount /100) *10;
Because i wrote like this, but with this (amount -= (amount /100) *10;) statement i can able to pass only 2 test cases of the problem.
Why ? Please explain.