0

What's wrong with my code?

Problem: 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. 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 My Code: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int result; for(int i = 1; i<=3; i++) { result = amount - amount*(10/100); System.out.println(result); } } }

18th Aug 2021, 3:18 AM
Abhishek Kumar
4 Respostas
+ 2
1. You divide integers and accordingly get the result of rounding to the nearest integer, that is, 10/100 = 0. 2. You only need one output of the final result, and you draw three conclusions. 3. You do not change the result of calculations during the cycle.
18th Aug 2021, 4:04 AM
Solo
Solo - avatar
+ 1
😃 They changed the condition of the task. Previously, it was required to calculate the remainder in six months, but now in three months and at the same time left the old example of the output of the result 🤣
18th Aug 2021, 4:36 AM
Solo
Solo - avatar
0
Well, thanks everybody for their solutions! Here, I'll provide you with the working code: 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 = 1; i<=3; i++) { amount = amount * 90/100; } System.out.println(amount); } }
19th Aug 2021, 1:10 AM
Abhishek Kumar
- 1
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*0.1; } System.out.println(amount); } }
18th Aug 2021, 5:13 AM
Sanidhya Varshney