+ 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); } } }
9 Respostas
+ 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
Paul K Sadler đđ
+ 1
Thanks Paul k Sadler
- 1
Please take a look at the forum rules:
https://www.sololearn.com/Content-Creation-Guidelines/
https://www.sololearn.com/Discuss/1316935/?ref=app
Take a look at these guides on how to ask a question.
https://stackoverflow.com/help/how-to-ask
https://www.sololearn.com/blog/38/8-simple-rules-to-get-help-from-the-community
Please always tag the language you're asking about.
https://code.sololearn.com/W3uiji9X28C1/?ref=app