0
Could somebody help me with this code?
Task description: 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: 14580 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 My code doesn't work. If you see the solution, make me know: https://code.sololearn.com/cmv7k4S828N0/?ref=app Thank you!
4 Answers
+ 1
Its working. Use double instead of int for amount variable.
+ 1
Black Winter thank you for your answer
0
There are hidden tasks there. I don't know what this means. 2 tasks are opened (and completed), where others aren't.
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
int payment=0;
//your code goes here
for(int i=0;i<3;i++){
payment=amount/10;
amount -= payment;
}
System.out.println(amount);
}
}