單一if
import java.util.Scanner; public class If { public static void main(String[] args) { int age; Scanner scn = new Scanner(System.in); System.out.println("Please enter age:"); age = scn.nextInt(); if (age < 20) System.out.println("You're underage,"); System.out.print("Can't vote yet."); } }