if ( num < 0 ) System.out.println("The number " + num + " is negative"); // true-branch else { System.out.println("The number " + num + " is 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.
At a movie theater box office a person less than age 17 is charged the "child rate". Otherwise a person is charged "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 has only one statement inside of it, but this is OK. All you need to do is complete the blank so the program picks the correct block for the age that was input.
Fill in the blank. You might wish to make a copy of the program in your editor, make your proposed correction, and run it to see if it works as you think.