Section 4.1 Using the Simple if Statement
Conditional statements in Python and Java are very similar. In Python we have three patterns:
In Python the simple
if statement is written as:
In Java, this same pattern requires two changes: the condition must be in parentheses
(), and the code block must be enclosed in curly braces {}.
Once again you can see that in Java the curly braces define a block rather than indentation. In Java, the parentheses around the condition are required because it is technically a function that evaluates to
True or False.
You have attempted of activities on this page.
