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


Please tell me where is the mistake

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(; 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); } } }

11/30/2021 7:38:35 PM

Achraf Soua

9 Answers

New Answer


Thanks jayakrishna it run


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


I need it to print one time


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


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


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


Paul K Sadler 👍👍


Thanks Paul k Sadler


Please take a look at the forum rules: Take a look at these guides on how to ask a question. Please always tag the language you're asking about.