+ 2

Whats the problem in this 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. */ import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(int i=1;i<=3;i++) { int Payment =amount*10/100; amount =amount-Payment; } System.out.println(Payment ); } }

26th Jan 2023, 6:44 PM
Dipika Padvi
3 odpowiedzi
+ 5
print amount finally. (Remaining amount) But you are printing Payment value.(which is Intrest)
26th Jan 2023, 6:53 PM
Jayakrishna 🇮🇳
+ 3
print amount instead of Payment!
26th Jan 2023, 7:08 PM
Abhi_Raftaar
Abhi_Raftaar - avatar
+ 2
Thank you i got the right ans👇 import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(int i=1;i<=3;i++) { int Payment =amount*10/100; amount =amount- Payment; } System.out.println(amount ); } }
27th Jan 2023, 3:22 AM
Dipika Padvi