I am trying to access variable outside an if statement in java. The variable is axeMinDmg. Here is what i have but getting an error. I want minDmg = axeMi
If you want to assign a variable to outside of if-else block, you can use ternary operator which represented by the : operator.
For example, the standard if-else Java expression:
int money;
if (shouldReceiveBonus()) {
price = 100;
}
else {
price = 50;
}
With ternary operator is equivalent to:
int money = shouldReceiveBonus() ? 100 : 50;