+ 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

9th Dec 2020, 3:21 PM
Amal Gil
Amal Gil - avatar
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); } }
9th Dec 2020, 3:27 PM
Иван Чикyнов
Иван Чикyнов - avatar
+ 2
carefully read the condition, it says that 10 percent is not deducted from the original amount
9th Dec 2020, 3:29 PM
Иван Чикyнов
Иван Чикyнов - avatar
+ 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();
9th Dec 2020, 3:35 PM
noteve
noteve - avatar
+ 1
Иван Чикyнов how did think about it in this way: Amount= amount *9/10;
9th Dec 2020, 3:37 PM
Amal Gil
Amal Gil - avatar
+ 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
9th Dec 2020, 3:41 PM
noteve
noteve - avatar