Answer:
if ( num < 0 )
System.out.println("The number " + num + " is negative."); // true-branch
else
{
System.out.println("The number " + num + " is zero or positive"); // false-branch
System.out.print ("Positive numbers are greater "); // false-branch
System.out.println("or equal to zero. "); // false-branch
}
System.out.println("Good-bye for now"); // always executed
The true branch has one statement. The false branch has one statement, a block containing three statements.
Practice
[Movie Tickets]At a movie theater box office a person less than age 13 is charged the "child rate". Otherwise a person is charged the "adult rate." Here is a partially complete program that does this:
In this program, the true branch and the false branch are both blocks. Each block contains only one statement, but this is OK. Often programmers do this for clarity.
QUESTION 11:
Fill in the blank so that a person under the age of 13 is charged the child rate.