Arrange what you want with 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:

+24 + 3 * -4
      ------
+24 +   -12
-----------
     12

Arrange what you want with Parentheses

To say exactly what numbers go with each operator, use parentheses. For example

-1 * ( 9 - 2 ) * 3  

means do 9 - 2 first. The "( )" groups together what you want done first. After doing the subtraction, the ( 9 - 2 ) becomes a 7:

-1 * 7 * 3  

Now follow the left-to-right rule for operators of equal precedence:

-1 * 7 * 3  
------
  -7   * 3
  --------
     -21

QUESTION 26:

What is the value of each of the following expressions?

Expression (8 - 2) / 2 (2 + 6) / 2 - 9 (8 + 4) * 2 8 + 4 * 2 8 + (4 * 2)
Value?