0

Loan Calculator Output

Hi, I can't seem to find exactly the answer to my problem in any of the other threads. I am trying to solve the Loan Calculator challenge for Java and my output is off by one number. Even if I sidestep it and decrease my answer by -1 it still says I'm doing it wrong. I assume I want to do the math differently but am not sure what exactly is the best way to do it using only integers and not a double as I need to decrease it by 10% each loop. My code is below. Thanks in advance! 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 x = 1; x <= 6; x++) { int payment = amount / 10; amount = amount - payment; System.out.println(amount); } } }

28th Jan 2021, 6:15 PM
David Amateau
David Amateau - avatar
3 Respostas
+ 1
David Amateau Try converting int variables to double and using Math.floor on final result
28th Jan 2021, 6:18 PM
Abhay
Abhay - avatar
+ 1
David Amateau You can try this logic. for(int i = 1; i <= 6; i++) { amount = amount * 90 / 100; } System.out.print(amount);
28th Jan 2021, 7:05 PM
A͢J
A͢J - avatar
0
This challenge leads to confusion quite frequently, so I tried to write a code to give some better insight into what's going on. I hope my explanations are not too confusing https://code.sololearn.com/ca5A14A10A15/?ref=app
29th Jan 2021, 1:31 AM
Benjamin Jürgens
Benjamin Jürgens - avatar