



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Unknown 1989;
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Review Char Double Expressions
double temp = x; x = y; y = temp; See Swap.java Special Increment and Decrement Operators Counting and adding 1 are common operations in computing. Remember when we counted the number of spaces in a sentence? There was a statement like: count = count + 1; This is such a common operation that Java has special operator for adding one - the increment operator: ++ int i = 4; i++; System.out.println("i = " + i ); The ++ operator can also be used as part of an expression on the RHS of an assignment statement: int a = 3; int b = 7; a = b++; The above ++ operator works like this: The value of the expression is evaluated before incrementing the variable - in this case, the value of the expression is 7. So, the above statements set the value of a to 7, and then increments b to 8. The above ++ occurs after the operator - this is called a postfix increment. There is also a prefix increment operation, where ++ is place in front of the variable: int a = 3; int b = 7; a = ++b; In this case, b is incremented before the expression is evaluated. So, b gets the value 8, and then this value (8) is assigned to a. Look at Increment.java Don't use these operations in arbitrary expressions - it can be very hard to read!
k = i++ * 3 + --j * 2; They can be very hard to read and comprehend! Precedence () None op++ op-- unary +,- Right ++op --op Right (cast) Right