Java: If else statement

This entry is part 7 of 54 in the series Learn Java

The if else statement will check if a condition is true.

In the below example, we set a string a to be “Elton”.

Since (a == “Elton”) will evaluate to true, the first println statement will be executed.

package javaapplication6;

public class JavaApplication6 {

    public static void main(String[] args) {
        String a = "Elton";
        if (a == "Elton")
            System.out.println("Crocodile Rock");
        } else
            System.out.println("Uptown Girl");


Series Navigation<< Java: String concatenation
Java: Conditional while loop >>

Leave a comment

Leave a Reply