(Review: ) Is the following a correct expression?

13 * 6 -

A good answer might be:

No.


Expressions

The literals (the integers) and the operators are out of order in the above incorrect expression. (One legal arrangement is     13 * -6    for 13 times minus 6.)

An expression is a combination of literals, operators, variables, and parentheses used to calculate a value.

Of course, the parts of an expression must be arranged correctly. The syntax of Java (or any programming language) describes the correct arrangements. The details of this will be left to another course (or your on-line documentation, if you care to dig through it.) The rules for correct Java expressions are about the same as for algebra.

We need to talk about operators and operands. You already know what an operator is (a symbol +, -, *, / that calls for an arithmetic operation.)

An operand is a value that is acted upon by an operator.

For example, in 13 - 5 the 13 and the 5 are the operands and the - is the operator. Examine the following expressions. Assume that each variable has already been correctly declared.

Expression Correct Not Correct Expression Correct Not Correct
25 25 - value
2( a - b ) (a-b) * (c-d)
A - b/c +D -sum + partial
( (x+y) / z ) / ( a - b ) ( (m - n) + (w-x-z) / (p % q )



QUESTION 2:

Are arithmetic expressions the only kind of expression?