if (condition) {
    //one or more statements
}

A few comments about the syntax above:
You may also follow an if with an else , and nest if-else statements as follows:
if(score > 90) {
    System.out.println("A");
} else {
    if(score > 80) {
        System.out.println("B");
    } else {
        if(score > 70) {
            System.out.println("C");
        } else {
            System.out.println("F");
        }
    }
}
    
As the example above demonstrates, it can get quite messy to test several conditions.  The above code can also be written as shown below using else if conditions.
if (x > 90) {
    System.out.println("A");
} else if (x > 80) {
    System.out.println("B");
} else if (x > 70) {
    System.out.println("C");
} else {
    System.out.println("F");
}
Following an if, you may have 0 or more else ifs and 0 or 1 else.

Once a condition is satisfied, the rest will not be tested.  In the example above, if score is 94, the first condition will be true, the program will print A, and skip the remaining else ifs.

The boolean operators && and || are used to chain together multiple conditions.  For example, to determine whether a particular string contains the characters x, y and z, y, you might do the following:
if(s.contains("a") && s.contains("b") && s.contains("c")) {
    //statements
}


Sign in  |  Recent Site Activity  |  Terms  |  Report Abuse  |  Print page  |  Powered by Google Sites