0

Java 2 error Loan Calculator

I am not sure what it is happing.. This is my code I did the same excersice in my computer and the error are the decimals import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //tu código va aquí int x=1,z=0; while(x<=6){ z= amount*10/100; amount = amount - z; x++; } System.out.println(amount); } }

14th Feb 2021, 6:13 PM
Francisco Guadarrama Sanchez
Francisco Guadarrama Sanchez - avatar
11 Réponses
+ 2
Francisco Guadarrama Sanchez Just do amount = amount * 90 / 100; inside while loop
14th Feb 2021, 7:05 PM
A͢J
A͢J - avatar
+ 8
I think this will help you. https://code.sololearn.com/cam4f1R38za2/?ref=app 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 i=0;i<6;i++){ amount -= (amount * 0.1); } System.out.println(amount); } }
15th Feb 2021, 5:04 PM
Wei Phyo Aung
Wei Phyo Aung - avatar
+ 2
double amount = scanner.nextDouble(); //tu código va aquí int x=1,z=0; while(x<=6){ z= (int)(Math.ceil(amount*10/100)); amount = amount - z; x++; } System.out.println((int)amount); } }
14th Feb 2021, 6:37 PM
Atul [Inactive]
+ 2
I Am AJ ! My code is fulfilled all the cases. Just check if my process is correct
14th Feb 2021, 7:42 PM
Atul [Inactive]
+ 2
Atul Your code is also correct. First time I did like that when I was getting difference 1.
15th Feb 2021, 3:32 AM
A͢J
A͢J - avatar
+ 2
I Am AJ ! Thanks
15th Feb 2021, 12:07 PM
Atul [Inactive]
+ 1
Make this necessary changes in your code
14th Feb 2021, 6:38 PM
Atul [Inactive]
+ 1
I Am AJ ! It worked perfectly, thank you so much
14th Feb 2021, 7:42 PM
Francisco Guadarrama Sanchez
Francisco Guadarrama Sanchez - avatar
+ 1
I Am AJ ! Yes, I modified my code with your code I could pass the test 🙂🙋🏻‍♂️thanks
14th Feb 2021, 7:45 PM
Francisco Guadarrama Sanchez
Francisco Guadarrama Sanchez - avatar
0
I will try it right now
14th Feb 2021, 6:38 PM
Francisco Guadarrama Sanchez
Francisco Guadarrama Sanchez - avatar
8th Mar 2021, 9:47 PM
AKHY EL MAHEDI
AKHY EL MAHEDI - avatar