0
Loan calculator problem answer differ from few values
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int value; //your code goes here for(int x=0;x<6;x++){ value=(amount/100)*10; amount-=value; } System.out.println(amount); } } My output:- 53150 Expected output:-53144
4 Answers
+ 4
Check my answer here.. I've explained why the test cases didn't pass.
Hope it helps!
https://www.sololearn.com/Discuss/2645314/?ref=app
+ 6
You're welcome đ
+ 3
https://code.sololearn.com/cp6GXE4Rc84v/?ref=app
The reason why you get 54145 is because of Integer division. It ignores decimals (rounding down). Ultimately when you do a minus, you get an extra 1.
1: 100000 - 100000/10 = 90000
2: 90000 - 90000/10 = 81000
3: 81000 - 81000/10 = 72900
4: 72900 - 72900/10 = 65610
5: 65610 - 65610/10 = 59049
6: 59049 - 59049/10
= 59049 - 5904 (missing precision)
= 54145 (extra 1, expected 54144)
To bypass, you can do "amount = amount * 90 / 100".
Do not hard-code -1 or +1.
One good example will be 0. After 6 months, it will still be 0. By hard-coding -1, it results in -1 which is wrong.
+ 1
Thank youđđfor your help