0

Please solve this problem.

I have defined an array in the main function inside a if statement. When I use that array in an if statement inside the main function, it says "symbol not found". Why?

18th Aug 2019, 6:04 AM
Gayani Abeykoon
Gayani Abeykoon - avatar
1 Resposta
+ 10
if(true){ int a=1;} System.out.print(a); //error: cannot find symbol //symbol: variable a something like this ? it happens because variable a is limited to the braces{} inside which it gets declared(int a;) you can remove this error by declaring variable a outside the if block: int a; if(true){ a=1;} System.out.print(a);
18th Aug 2019, 6:06 AM
Gaurav Agrawal
Gaurav Agrawal - avatar