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?
1 Odpowiedź
+ 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);