+ 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 ); } }
3 Respostas
+ 5
print amount finally. (Remaining amount)
But you are printing Payment value.(which is Intrest)
+ 3
print amount instead of Payment!
+ 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 );
}
}