Java Tutorial Java Advanced Java Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Java if Keyword

The Java if keyword is used to create a block of conditional statements which executes only when the condition is true.



Flow Diagram:

java If Loop


In the example below, the if code block is created which executes only when the variable called i is divisible by 3.

public class MyClass {
  public static void main(String[] args) {
    int i = 15;
    if (i % 3 == 0)
      System.out.println(i+" is divisible by 3.");

The output of the above code will be:

15 is divisible by 3.

❮ Java Keywords