For clarity, the problem is here:
if(a==10)
int x=20;
... and a mistake error: variable declaration not allowed here.
This is not allowed because there is a specific list of operators that are allowed after if; they are described in detail in JLSยง14.5 :
StatementWithoutTrailingSubstatementLabeledStatementIfThenStatementIfThenElseStatementWhileStatementForStatement
StatementWithoutTrailingSubstatement (the first thing mentioned above) includes:
BlockEmptyStatementExpressionStatementAssertStatementSwitchStatementDoStatementBreakStatementContinueStatementReturnStatementSynchronizedStatementThrowStatementTryStatement
, LocalVariableDeclarationStatement . LocalVariableDeclarationStatement Block, , .
? , , . , ? , . ? if? , ? , (, int x = foo();), , (foo();). if ( ), , ? , , , if ...