Box Office Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

if ( age < 13  )

Box Office Program

Here is the program with the blank filled in correctly:

import java.util.Scanner;
class BoxOffice
{
  public static void main (String[] args) 
  {
    Scanner scan = new Scanner( System.in );
    int age;
 
    System.out.println("Enter your age:");
    age = scan.nextInt();

    if ( age < 13  )
    {
      System.out.println("Child rate.");   
    } 
    else
    {
      System.out.println("Adult rate.");   
    }
    System.out.println("Enjoy the show.");    
  }
}

Here is what happens for one run of the program:

  1. The program prints "Enter your age".
  2. The user enters an age: "21", for example.
  3. The string "21" is converted from characters into an int and put into the variable age.
  4. The condition age < 13 is tested.
  5. 21 < 13 is false.
  6. The false branch is executed: the program prints "adult rate".
  7. Execution continues with the statement after the false branch: "Enjoy the show" is printed.

QUESTION 12:

What does the program output if the user enters 11?