0

Java, scanner problem

Hi, I am trying to run a code below 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 (i=1; i<=3; i++){ amount = amount * 0.9 ; } System.out.println("Your debt is " + amount ); } } But it gave a mistake Line 0 Cannot resolve symbol And that is code from exercise and have been written by content developer, not me. and it is started somehow from line 1 (my guess line 0 is hidden from pupils) Can somebody tell me what I am doing wrong? Thanks in advance

7th Dec 2021, 3:33 PM
Антон Курганский
Антон Курганский - avatar
7 Respostas
+ 1
Антон Курганский You didn't declare i You cannot assign double value to int and don't print anything except only value. for (int i=1; i<=3; i++){ amount = amount * 90 / 100 ; } System.out.println( amount );
7th Dec 2021, 3:34 PM
A͢J
A͢J - avatar
+ 1
Okay, I understood, thank you for so fast answer, that was helpful!
7th Dec 2021, 4:01 PM
Антон Курганский
Антон Курганский - avatar
+ 1
Declare your i and change amount by variable i in the for loop and also close the scanner.
8th Dec 2021, 5:16 AM
Vishal Pandey
0
Thank you very much! Question for future, debagger here doesn't point to line with mistake?
7th Dec 2021, 3:38 PM
Антон Курганский
Антон Курганский - avatar
0
Антон Курганский It gives just try to run again.
7th Dec 2021, 3:41 PM
A͢J
A͢J - avatar
0
Yes ,code works fine now, but now I don't understand why it doesn't take something like (double) amount = (double) amount * 0.9; 🤔 And question about debagger, why it pointed for me to "line 0", not like "line 9"?
7th Dec 2021, 3:44 PM
Антон Курганский
Антон Курганский - avatar
0
Антон Курганский You declared amount as int so (double) amount would be wrong. You need to assign it to another variable with double data type double abc = (double) amount; abc = (double) amount * 0.9; So basically you need to take input as double if you want to solve like that. About error that's the problem of Sololearn terminal. I think they put as alert so we get message like that.
7th Dec 2021, 3:54 PM
A͢J
A͢J - avatar