+ 3

Please tell me where is the mistake

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 i=1;i<=3;i++){ int payment =((amount*10)/100); int remaining=(amount-payment); System.out.println(remaining); } } }

30th Nov 2021, 7:38 PM
Achraf Soua
9 Respostas
+ 2
Thanks jayakrishna it run
30th Nov 2021, 8:55 PM
Achraf Soua
+ 1
1) you are printing 3 times remaining amount. Do you need 3 times or Only ones. Achraf Soua 2) int/int results int only so take a double as 100.0 instead of 100 there and cast back to int edit: take out if loop Printing for (int i=1;i<=3;i++){ int payment =((amount*10)/100); amount=(amount-payment); } System.out.println(amount); See amount calculation. pointed by @Paul K Sadler
30th Nov 2021, 7:53 PM
Jayakrishna 🇼🇳
+ 1
I need it to print one time
30th Nov 2021, 8:06 PM
Achraf Soua
+ 1
The problem is you are calculating on amount but not reducing amount with each iteration of the loop. The 10% on the second payment needs to be calculated on the reduced amount due after the second payment. Likewise the 10% for the third payment needs to be calculated on the amount after the second payment. if you need more help let us know. EDIT You can further simplify the code like this: for(int i=1; i<=3; i++) { amount *= 0.9; } System.out.println(amount);
30th Nov 2021, 8:10 PM
Paul K Sadler
Paul K Sadler - avatar
+ 1
Achraf Soua your welcome. But The amount calculation mistake identification should be credited to @Paul K Sadler. I am not observed it first.
1st Dec 2021, 9:07 AM
Jayakrishna 🇼🇳
+ 1
Jayakrishna🇼🇳 The important thing is we worked together to help Achraf Soua to understand. It was a pleasure to do so 🙂
1st Dec 2021, 9:14 AM
Paul K Sadler
Paul K Sadler - avatar
+ 1
Paul K Sadler 👍👍
1st Dec 2021, 9:16 AM
Jayakrishna 🇼🇳
+ 1
Thanks Paul k Sadler
1st Dec 2021, 9:29 AM
Achraf Soua
30th Nov 2021, 7:43 PM
Simon Sauter
Simon Sauter - avatar