Alice and Bob

Report a typo

Complete the program that takes Alice's and Bob's ages as input and determines whether Alice is older, younger, or the same age as Bob.

Fill in the gaps with the relevant elements
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int aliceAge = scanner.nextInt();
        int bobAge = scanner.nextInt();

        String comparisonResult;
        if (aliceAge  bobAge) {
            comparisonResult = "older than";
        } else if (aliceAge  bobAge) {
            comparisonResult = "the same age as";
        } else {
            comparisonResult  "younger than";
        }

        System.out.println("Alice is " + comparisonResult + " Bob.");
    }
}

Create a free account to access the full topic