Spaces Don't Much Matter

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:

Multiplication must be shown with a * operator. (Another answer is that 3.14y is not a correct variable name.)

Spaces Don't Much Matter

An expression can be written without using any spaces. Operators and parentheses are enough to separate the parts of an expression. You can use one or more spaces in an expression to visually separate the parts without changing the meaning. For example, the following is a correct expression:

(hoursWorked*payRate)-deduction

The following means exactly the same:

(hoursWorked * payRate) - deduction

Use spaces wisely to make it clear what the expression means. By making things clear, you might save yourself hours of debugging. Spaces can't be placed in the middle of identifiers. The following is NOT correct:

( hours Worked * pay Rate) -deduction

It is possible (but not nice) to be deceptive with spaces. For example, in the following:

12-4   /   2+2

it looks as if 4 is subtracted from 12, and then that the result, 8, is divided by 4. However, the spaces don't count, and the expression is the same as:

12 - 4/2 + 2

This arrangement of spaces makes it clear what the expression means.

QUESTION 21:

Based on what you know about algebra, what is the value of the above expression?