Title | Exam1-practice - CS1101 PRACTICE EXAM 1 |
---|---|
Course | Programming & Prob Solv |
Institution | Vanderbilt University |
Pages | 6 |
File Size | 229.5 KB |
File Type | |
Total Downloads | 65 |
Total Views | 142 |
CS1101 PRACTICE EXAM 1...
CS 1101 –Programming and Problem Solving
Exam 1 Practice Problems The following practice problems are to inform you of the kinds of things you are expected to know for the exam. This is NOT designed to give you an idea of the length of the exam (read as the actual exam might be shorter or longer). 1.
2.
Expressions. For each of the following expressions, please provide the value that the expression would produce. Be careful to express the value properly. If the value is an integer value, make sure that you do not include a decimal point. If the value is a floating point value, be sure to include a decimal point. If the value is a boolean/logical value, be sure to write either true or false. If the value is a string value, be sure to write it in double quotes. If the expression is not valid (for whatever reason), write error. (a) (5 + 7 + "=" + 5 + 7)
(a)
(b) (4 / 0 * 2 + 6)
(c)
(c) (10 / 3 + (double)2 / 8)
(d)
Identifiers (6 × 2 pts = 12 pts) Indicate for each of the following if it is a legal Java identifier that could be used as a variable name or a method name. If the answer is no, explain why it is not legal. This questions deals with which identifiers are legal; it is not a question about style or naming conventions. (a) i love CS
Yes
No
(b) BLACK&GOLD
Yes
No
(c) a123456789
Yes
No
3. Operator precedence: Rewrite the following Java expression so that it is an equivalent fully parenthesized Java expression according to the order in which the expression would be evaluated. X – 8 == Z && 40 < X / 2 – Z || 40 > Y
4. Boolean evaluation: The two expressions below are logically equivalent. Give a set of values for x, y and z when both boolean expressions produce a result of TRUE.
• •
Expression 1: (! ((x % 2 == 0) && (y > z))) Expression 2: (! (x % 2 == 0) || !(y > z))
5. Assume the following integer variables have the associated values: a = 2, b = 4, and c = 0. Indicate by circling T or F or I for each of the following Java logical expressions depending on whether it evaluates to True or False or is Invalid. a) a == 4 || b < 2
T
F
I
b) c != 0 && a/c > 3
T
F
I
c) b%a == c && a*a!=b
T
F
I
d) !(a >= b || a >= -1)
T
F
I
e) 1...