0

credit calculator. what's wrong?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int remainder = 3; for (int i = 1; i <= remainder; i ++) { amount = amount - ((amount/100)*10); i ++; } System.out.println(amount); } }

4th Jan 2023, 6:19 AM
Nick Vol
Nick Vol - avatar
4 Respostas
+ 2
In you loop, you have i++ twice: Once in the head if the loop, once after calculating the amount. So on everniteration of the loop, i is not only increased by 1, but by 2. You can remove the i++ after amount.
4th Jan 2023, 9:51 AM
Lisa
Lisa - avatar
+ 1
Great that you could solve it! :)
4th Jan 2023, 9:56 AM
Lisa
Lisa - avatar
0
Thanks a lot! Problem solved i++ deleted, i=0
4th Jan 2023, 9:54 AM
Nick Vol
Nick Vol - avatar
0
Thank you for writing
4th Jan 2023, 9:58 AM
Nick Vol
Nick Vol - avatar