(You can go to the MathCS lab, login to one of the machines and print it out. Pick up your print outs by the lab rep (at the entrance of the MathCS lab). You can also print in the library, but that will cost you some money).
You must use the answer sheet
int x, y z; x = 4; y = 4; z = 5; z += y *= x -= 2; System.out.println(x); x = ____________ (3 pts) System.out.println(y); y = ____________ (3 pts) System.out.println(z); z = ____________ (4 pts) x = 3; y = 4; z = x++ * --y; System.out.println(x); x = ____________ (3 pts) System.out.println(y); y = ____________ (3 pts) System.out.println(z); z = ____________ (4 pts) |
If there is an error, describe the error and if there is no error, give the value stored by the assignment statement.
Answer each question with the original values of the variables !!!
Original values of the variables: byte b1 = 3, b2 = 5, b3 = 7; int i1 = 3, i2 = 5, i3 = 7; double d1 = 3.0, d2 = 5.0, d3 = 7.0; String s1 = "3", s2 = "5", d3 = "7"; b1 = b2; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ b1 = -b2; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ b1 = b2 + b3; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ i1 = b2 + b3; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ d1 = b2 + b3; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ s1 = b2 + b3; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ s1 = s2 + b3; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ s1 = b3 + s2; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ s1 = b3 - b2 + s2; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ s1 = s2 + b3 - b2; // Error: Y / N // If Y, reason, if N, assigned value: ____________________________ |
Note: there is no − (minus) operation defined for String in Java.
If there is no error, give the result (true or false) of the Boolean expression.
Answer each question with the original values of the variables !!!
Original values of the variables: int i = 4; double x = 4; 'a' > 'A' Error: Y / N If no error, result = true / false i > x && i > 3 && x > 3 Error: Y / N If no error, result = true / false 0 < i < 10 Error: Y / N If no error, result = true / false ++i > 4 Error: Y / N If no error, result = true / false i++ > 4 Error: Y / N If no error, result = true / false |
char c; 1111111111222 01234567890123456789012 String s = "How are you doing today"; |
You can assume that the char typed variable c is initialized with a Unicode of some character.
Questions:
|