+ 3
What is the error please in my code
I should calculate the remaining amount of a loan that I took from a freind after 6 months. For your information that you pay him back 10%of the loan each month. How much it remains to pay him all the loan after 6 months. https://code.sololearn.com/cve2oZJ8G3b9/?ref=app
7 Respostas
+ 5
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 x = 1; x <= 6; x++){
amount = amount * 9 / 10;
}
System.out.println(amount);
}
}
+ 2
carefully read the condition, it says that 10 percent is not deducted from the original amount
+ 2
Иван Чикyнов 's code is right but in case you want the result to be EXACT (or with decimal places)
//just replace
int amount = scanner.nextInt();
//with
double amount = scanner.nextInt();
+ 1
Иван Чикyнов how did think about it in this way:
Amount= amount *9/10;
+ 1
amal 01
9 / 10 = 0.90 = 90%
So multiplying by its 90% means subtracting by its 10%.
e.g.
10 * 9 / 10 = 10 * 0.9 = 9 (which is equal to 10 - 1 and 1 is the 10% of 10) and so on