Things You'll Need:
- A computer with Java set up on it
-
Step 1
Think about the condition or expression you are trying to check. Often it helps to think about this in a sentence form.
For example:
If it is raining outside, then I will wear a rain jacket. In this case, the condition we are trying to check is if it is raining outside.
Conditions must have a boolean value - meaning they either are true or false. -
Step 2
Now think about the result or what you want to happen if the conditional (or expression) you thought about above is true.
In the example above that would be wearing a rain jacket. -
Step 3
Put this in a form that java can understand:
if (expression)
resulting-statement;
In english, this says, if the expression is true, then do the resulting statement. -
Step 4
If you have multiple statements that you want to happen if the condition is true, then you can surround them with parenthesis.
if (expression)
{resulting-statement;
resulting-statement2;
}
Notice that now we are grouping the statements with braces. So in this case, if the expression is true, then it would execute all the statements within the braces.












