Page 148 - Introduction to Programming with Java: A Problem Solving Approach
P. 148

                114 Chapter 4 Control Statements
 1. grouping with parentheses: (<expression>)
2. unary operators: +x
-x
(<type>) x x++
x--
!x
3. multiplication and division operators: x* y
x/ y
x% y
4. addition and subtraction operators: x+ y
x– y
5. less than and greater than relational operators: x< y
x> y
x <= y
x >= y
6. equality operators: x == y
x != y
7. “and” logical operator: x && y
8. “or” logical operator: x || y
Apago PDF Enhancer
Figure 4.6 Abbreviated operator precedence table (see Appendix 2 for complete table)
The operator groups at the top of the table have higher precedence than the operator groups at the bottom of the table. All operators within a particular group have equal precedence. If an expression has two or more same- precedence operators, then within that expression ones on the left are executed before ones on the right.
if (temp >= 50 && temp <= 90)
You may include these extra parentheses or not, as you wish. We included them in Figure 4.5 to emphasize the order of evaluation in this initial presentation, but in the future we will often omit them to minimize clutter.
Another Example
For another example, consider commercial promotions at sports events. Suppose the local Yummy Burgers restaurant is willing to provide free French fries to all fans at a basketball game whenever the home team wins and scores at least 100 points. The problem is to write a program that prints the following message whenever that condition is satisfied:








































































   146   147   148   149   150