Skip to main content

Java For Python Programmers Edition 2

Section 4.2 Using the if - else Statement

The Java equivalent follows the same syntactical rules as before.
public class IfElseExample {
    public static void main(String[] args) {
        int age = 16;
        if (age >= 18) {
            System.out.println("You can vote.");
        } else {
            System.out.println("You are not yet eligible to vote.");
        }
    }
}
You have attempted of activities on this page.