CMSC 131A Study Guide - Midterm Guide: Operand, Gif, Truetype

124 views29 pages

Document Summary

The result of some expressions were assigned to variables, others were passed to methods (such as when printing) and others were themselves used as part of larger expressions. Consider the following code public static void main(string[] args) { It will compile and print 1 1 to the screen. We need to be careful with how we use these. x++; //post increment. ++x; //pre increment x+=val; // add that val to x. What do you think the output is? int x,y; x=2; y=5; In java they are (top being higher precedence) If two operators have the same precedence, then they are generally evaluated from left to right on the line. However, assignments are actually done from right to left! x = y = z = 4; So, what is the output of the following? int x=1, y=1, z; If (x++ > 5 && y-- < 5) { z = 10; else { z = 20;