if ( booleanExpression ){
    one or more statements
}else {
    one or more statements }

Answer:

Yes. Logically it is the same as:

if ( booleanExpression )
{
    one or more statements
}
else 
{
    one or more statements 
}

Some programmers use the first style to "save" lines. This was once desirable when computer terminals could display only 23 lines. But the style leads to errors and extra debugging time.

Asking the Right Question

Say that you are shopping at the Mall and find a $44.95 sweater you like, but, due to an impulsive cookie purchase, you might not have enough money to buy it. Here is a program that decides if you get the sweater:

import java.util.Scanner;
class SweaterPurchase
{
  public static void main (String[] args)
  { 
    final int price = 4495;    // price in cents

    Scanner scan = new Scanner( System.in );
 
    int cash;                       

    System.out.println("How much do you have, in pennies?");
    cash   = scan.nextInt();     
    
    if (   )
      System.out.println("You can buy the sweater" );
    else
    {
      System.out.println("You can't buy the sweater" );
      System.out.println("You need $" + 
        (price-cash)/100 + "." + (price-cash)%100 + " more." );
    }

  }
}

The reserved word final in the fifth line says that the value held in price will not change during the run of the program. When you use final, the compiler will not let you write a statement that tries to change the value. This is useful for preventing bugs.

QUESTION 7:

What boolean expression should be in the blank? (Assume that there is no sales tax.)