Answer the question
In order to leave comments, you need to log in
In what cases, it is possible to omit parentheses in the if construct and will it be correct?
Good afternoon guys!
Tell me, is the code below aesthetically correct? Or does the aesthetics of writing code say that you should always put brackets? Or again, it's all a matter of taste?
public class TestII {
public static void main(String[] args) {
int a = 10;
int b = 11;
if (a < b)
System.out.println("True.");
else
System.out.println("False");
}
}
Answer the question
In order to leave comments, you need to log in
By convention, parentheses should always be:
Note:if statements always use braces {}. Avoid the following error-prone form:
if (condition) //AVOID! THIS OMITS THE BRACES {}!statement;
proof: https://www.oracle.com/technetwork/java/codeconven...
IMHO:
But there may be exceptions:
- personal project
- agreements within the team.
And these exceptions work until someone else starts working or reading with this code - in this case, it is advisable to adhere to the standards.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question