I have to find out remaining amount after 3 months , so please help me to find the error or my mistake . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have to find out remaining amount after 3 months , so please help me to find the error or my 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 do{ System.out.println("Remaining amount: "+remain); } while(amount>0);{ int remain= ((amount/100)*10); } } }

9th Nov 2021, 7:06 AM
āĻŽā§‹āĻšāĻžāĻŽā§āĻŽāĻĻ āĻ¨āĻžāĻœāĻŽā§āĻ˛ āĻ‡āĻ¸āĻ˛āĻžāĻŽ
āĻŽā§‹āĻšāĻžāĻŽā§āĻŽāĻĻ āĻ¨āĻžāĻœāĻŽā§āĻ˛ āĻ‡āĻ¸āĻ˛āĻžāĻŽ - avatar
3 Answers
+ 1
It would be good if you take a look at do-while loop lesson once https://www.sololearn.com/learn/Java/2206/?ref=app
9th Nov 2021, 7:36 AM
Simba
Simba - avatar
+ 1
āĻŽā§‹āĻšāĻžāĻŽā§āĻŽāĻĻ āĻ¨āĻžāĻœāĻŽā§āĻ˛ āĻ‡āĻ¸āĻ˛āĻžāĻŽ check proper syntax of do while loop and also don't print anything else except result. Semicolon is used to break statement. You have used after while condition which is right in do while but there should not be any block after while condition. do { //statements } while(condition); this is the proper syntax of do while loop.
9th Nov 2021, 2:19 PM
AÍĸJ
AÍĸJ - avatar
+ 1
Logic and syntax issues: The do/while loop can run forever because (amount>0) never changes inside the loop. Inside the loop, remain is undefined. After the loop, remain is defined and calculated once, but it is enclosed by braces in its own block where it is never used. It is invisible to the rest of the program outside of the block. Recommendations: Instead of do/while, use a for() loop to reduce the principle amount 3 times, representing 3 months of payments. Instead of printing inside the loop, after the loop print the remaining principle amount. Don't print any text. Only print the number. The output must match exactly what Code Coach requires. EDIT: When the program calculates remain, it calculates a payment instead of the remaining amount. The payment should be subtracted from the remaining amount.
9th Nov 2021, 3:30 PM
Brian
Brian - avatar