# Lecture04 - Expressions Data Conversion and Input Expressions Operators and Precedence Assignment Operators Data Conversion Input and the Scanner

This preview shows pages 1–8. Sign up to view the full content.

1 Expressions, Data Conversion, and Input Expressions Operators and Precedence Assignment Operators Data Conversion Input and the Scanner Class Reading for this class: L&L, 2.4-2.6, App D

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Expressions An expression is a combination of one or more operators and operands Arithmetic expressions compute numeric results and make use of the arithmetic operators: If either or both operands used by an arithmetic operator are floating point, then the result is a floating point Addition + Subtraction - Multiplication * Division / Remainder %
3 Division and Remainder If both operands to the division operator ( / ) are integers, the result is an integer (the fractional part is discarded) The remainder operator (%) returns the remainder after dividing the second operand into the first 14 / 3 equals 8 / 12 equals 4 0 14 % 3 equals 8 % 12 equals 2 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Operator Precedence Operators can be combined into complex expressions result = total + count / max - offset; Operators have a well-defined precedence which determines the order in which they are evaluated Multiplication, division, and remainder are evaluated prior to addition, subtraction, and string concatenation Arithmetic operators with the same precedence are evaluated from left to right, but parentheses can be used to force the evaluation order See Appendix D for a more complete list of operators and their precedence.
5 Operator Precedence What is the order of evaluation in the following expressions? a + b + c + d + e 1 4 3 2 a + b * c - d / e 3 2 4 1 a / (b + c) - d % e 2 3 4 1 a / (b * (c + (d - e))) 4 1 2 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Expression Trees The evaluation of a particular expression can be shown using an expression tree The operators lower in the tree have higher precedence for that expression a + (b – c) / d a + / - d b c
7 Assignment Revisited The assignment operator has a lower

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/25/2010 for the course CS 110 taught by Professor Wilson during the Spring '10 term at University of Massachusetts Boston.

### Page1 / 23

Lecture04 - Expressions Data Conversion and Input Expressions Operators and Precedence Assignment Operators Data Conversion Input and the Scanner

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online