0

Java

A problem with Java lesson : I try to resolve code for loan counter but it seems to bug with line 0. Why ?

25th Aug 2022, 12:24 PM
Cédric De Craim
Cédric De Craim - avatar
6 odpowiedzi
+ 1
The statement int rem -= amount/10; is invalid statement. If it is about loan calculator for 3 months then your logic also not correct. If you are trying loop 3 times then correct way is int rem = 0; while( rem < 3 ) { /* add calculate statements here */ rem++; } For the calculation, calculate 10% and deduct it from total amount. The result is new current amount. Repeating this 3 times by loop, give you the desired result. And only after loop, print the result. In the loop, it prints 3 times.. Hope you can try it again now..
25th Aug 2022, 12:41 PM
Jayakrishna 🇮🇳
+ 1
No. I think you need to revise the lessons of basics variable declaration and initializations before attempting the practice.. You did the same mistake. int rem = scanner.nextInt() ; // assigns input into rem variable. (not to amount) . And redeclaration same variable in loop don't work. and amount is undefined. Declare and initialize before using any variable. In your previous code, declaring and assigning amount is properly done. Given in the task itself. Dont change those anything.. You just need to add remaining code to complete it. How to run loop, 3 times : I added code in my previous code with proper declarations. Only do this : In loop : 1) calculate 10% amount, sunbract it from amount, assign back result into amount. 2) display amount after loop. // not rem. Just 2 lines of code you need to write. What will be your tries for these two lines? Arrage remaining code as per my explanation in last 2 replys..
25th Aug 2022, 1:52 PM
Jayakrishna 🇮🇳
0
Please share your attempt here so that it helps you find where is problem? along with task description.
25th Aug 2022, 12:29 PM
Jayakrishna 🇮🇳
0
It shows : line 0, ; expected ?? import java.util.Scanner; public class Program { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); int rem -= amount/10; while(rem<=3){ System.out.println (rem); rem --;} } }
25th Aug 2022, 12:33 PM
Cédric De Craim
Cédric De Craim - avatar
0
Ok I understand here is my try: but still the same problem import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int rem = Scanner.nextIn(); do { int rem -= amount%10;} while(rem<3); System.out.println (rem); rem++; }}
25th Aug 2022, 1:38 PM
Cédric De Craim
Cédric De Craim - avatar
0
Me too same issue
26th Aug 2022, 2:57 PM
Daniel Micheal
Daniel Micheal - avatar