Number Tester

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:

-12 is negative.

Number Tester

An integer may be negative, or not. If it is not negative, then it is positive or zero. Here is that idea expressed as a flow chart:

[flowchart of two way decision]

The diamond box shows a two-way decision. Either the false branch or the true branch is taken depending on whether

num < 0

is true or false.

The "two-way split" of the program is easy to see in a two dimensional chart. It is harder to see this in a program where line follows line one after another. The flow chart shows the overall logic of the program. Most of the details of syntax are left out. It is often helpful to sketch a flowchart when you are designing a program. You can use the flowchart to get the logic correct, then fill in the details when you write the program.

QUESTION 5:

The user runs the program and enters "12". What will the program print?