When I try to run this code:
public static void main(String[] args) {
double salary = 10.1;
if (salary >= 100.3)
double number = salary * 10;
else
double number = salary * 20;
}
I get the following errors:
Syntax error on token "double", delete this token
and that both:
number cannot be resolved to a variable
Now the code is purposely bad, as it is a question where we have to state everything that's wrong with it.
As far as I understand, it's best practice to not declare the same variable twice and it's best to always use curly brackets; but why does the double number = salary * 10;
and double number = salary * 20;
cause an issue if curly brackets aren't used? I would've thought that would still compile and run correctly (it works if the brackets are used).