Extra Parentheses

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:

Expression (8 - 2) / 2 (2 + 6) / 2 - 9 (8 + 4) * 2 8 + 4 * 2 8 + (4 * 2)
Value? 3 -5 24 16 16

Extra Parentheses

Notice that the last expression (above) did not need parentheses. It does not hurt to use parentheses that are not needed. For example, all of the following are equivalent:

a + b + c * d a + b + (c * d) (a + b) + (c * d) ((a + b) + (c * d))

Warning! Look out for division. The / operator is a constant source of bugs! Parentheses will help.

QUESTION 27:

What is the value of each of the following expressions?

Expression 8 + 2 / 2 + 3 (8 + 2) / (2 + 3) (8 + 2) / 2 + 3 8 + 2 / (2 + 3)
Value?