CIS 180: Object-Oriented Programming

Laboratory Exercise #6




This lab exercise is intended to help improve your understanding of Java expressions.

Exercises

Consider the following declarations, and give the type and value of each expression in the table below. If the expression is not syntactically correct or will result in an error when evaluated, write "error".

For each expression, first try to determine the type and value without using the computer, then check your answers. You can find the values by printing them out, or by using the debugger. To determine the type, assign the value to an incompatible variable and inspect the error message that the compiler displays.

int i = 10, j = 5, k = 0;
boolean p = true, q = false;

Expression

Type / Value

(k < j) && (i < j)

 

(i < k) || (k < j)

 

i > j > k

 

!(j > k)

 

p || (j/k > 5)

 

p != q

 

(!p) == (k/j > j)

 

(i > j) | (j/k) < k

 

q ^ (p & !((k + 10) != i))

 

q = p