Chapter III Part II

# Chapter III Part II - Introduction to Control Statements II...

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

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

View Full Document

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

View Full Document

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

View Full Document

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.

Unformatted text preview: Introduction to Control Statements II IT108 George Mason University Conditional Operator if (x > 0) y = 1 else y = -1; is equivalent to y = (x > 0) ? 1 : -1; (booleanExpression) ? expression1 : expression2 Ternary operator Binary operator Unary operator Conditional Operator if (num % 2 == 0) System.out.println(num + “ is even”); else System.out.println(num + “ is odd”); System.out.println( (num % 2 == 0)? num + “ is even” : num + “ is odd”); Conditional Operator, cont. (booleanExp) ? exp1 : exp2 Miscellaneous Topics • Number literals • Translation of arithmetic expressions into Java • Getting input using Scanner • Comments, Naming Conventions, Styles • Short-circuit evaluation 6 Number Literals A literal is a constant value that appears directly in the program. For example, 34, 1,000,000, and 5.0 are literals in the following statements: int i = 34; long x = 1000000; double d = 5.0; 7 Integer Literals An integer literal can be assigned to an integer variable as long as it can fit into the variable. A compilation error would occur if the literal were too large for the variable to...
View Full Document

## This note was uploaded on 01/26/2012 for the course IT 108, 103, taught by Professor Bruno during the Spring '11 term at George Mason.

### Page1 / 16

Chapter III Part II - Introduction to Control Statements II...

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

View Full Document
Ask a homework question - tutors are online