Java incorporates standard mathematical logical conditions, including:
You can utilize these conditions to execute various actions based on different decisions. Java provides the following conditional statements:
Use an if statement to define a block of Java code that will be executed if a specified condition is true.
|
Keep in mind that “if” must be written in lowercase letters. Using uppercase letters (If or IF) will result in an error. |
In the given example, we evaluate two values to determine whether 20 exceeds 18.
If this condition proves true, display a specified text.
|
Variables can also undergo testing:
|
In the example above, we use two variables, x and y, to check if x is greater than y using the >
operator. Since x is 20 and y is 18, and we know that 20 is greater than 18, we print "x is greater than y" to the screen.