0
Java
A problem with Java lesson : I try to resolve code for loan counter but it seems to bug with line 0. Why ?
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..
+ 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..
0
Please share your attempt here so that it helps you find where is problem? along with task description.
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 --;}
}
}
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++;
}}
0
Me too same issue