 Please tell me where is the mistake | Sololearn: Learn to code for FREE!

+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); } } }

+2

Thanks jayakrishna it run

+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

+1

I need it to print one time

+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);

+1

Achraf Soua your welcome. But The amount calculation mistake identification should be credited to @Paul K Sadler. I am not observed it first.

+1

Jayakrishna🇮🇳 The important thing is we worked together to help Achraf Soua to understand. It was a pleasure to do so 🙂

+1

+1

-1