Docsity

Java Quiz: Operator Precedence and Identifiers, Exercises of Computer Science

Toggle sidebar
bg1
Signature _____________________
CSE 11
Name ________________________
Quiz 1
cs11f ____
Fall 2008
Student ID ____________________
This quiz is to be taken by yourself with closed books, closed notes, no calculators.
(Partial) Operator Precedence Table
Operators Associativity
* / % left to right
+ - left to right
< <= > >= left to right
== != left to right
&& left to right
|| left to right
= right to left
1) Which of the following are not valid Java identifiers? (Circle your answer(s).)
3rdLine Ugly_Betty one/two Int
nine2five lower-half Seven%Solution Ex2_3_4
2) Using the operator precedence table above, evaluate each expression and state what gets printed. Remember
short-circuit evaluation with && and ||.
int x = -2;
int y = -1;
int z = 4;
boolean b = x + y < z || 4 * y + z > x && x > y;
System.out.print( "b = " + b ); ____________________
b = (x + y < z || 4 * y + z > x) && x > y;
System.out.print( "b = " + b ); ____________________
x = z + 6 % 4 + y * 2;
System.out.print( "x = " + x ); ____________________
3) What color is described by the object
new Color( 255, 0, 0 ) ________________
Which of the following would be considered light gray? (Circle your answer.)
a) new Color( 200, 200, 200 ); b) new Color( 125, 125, 125 );
c) new Color( 55, 55, 55 );
(Continued on other side)
pf2

Partial preview of the text

Download Java Quiz: Operator Precedence and Identifiers and more Exercises Computer Science in PDF only on Docsity!

Signature _____________________ CSE 11 Name ________________________

Quiz 1

cs11f ____ Fall 2008 Student ID ____________________

This quiz is to be taken by yourself with closed books, closed notes, no calculators.

(Partial) Operator Precedence Table

Operators Associativity

* / % left to right

+ - left to right

< <= > >= left to right

== != left to right

&& left to right

|| left to right

= right to left

1) Which of the following are not valid Java identifiers? (Circle your answer(s).)

3rdLine Ugly_Betty one/two Int nine2five lower-half Seven%Solution Ex2_3_

2) Using the operator precedence table above, evaluate each expression and state what gets printed. Remember

short-circuit evaluation with && and ||.

int x = -2;int y = -1; int z = 4;boolean b = x + y < z || 4 * y + z > x && x > y; System.out.print( "b = " + b ); ____________________ b = (x + y < z || 4 * y + z > x) && x > y; System.out.print( "b = " + b ); ____________________ x = z + 6 % 4 + y * 2; System.out.print( "x = " + x ); ____________________

3) What color is described by the object

new Color( 255, 0, 0 ) ________________

Which of the following would be considered light gray? (Circle your answer.)

a) new Color( 200, 200, 200 ); b) new Color( 125, 125, 125 ); c) new Color( 55, 55, 55 );

(Continued on other side)

4) What Java keyword is used to specify an identifier is constant (cannot be changed once it is set)?

__________________

5) What would you expect from the following statements? Assume count = 25.

System.out.println( "The count is : + count โ€“ 3" );


System.out.println( "The count is: " + ( count + 2 ) );


System.out.println( "The count is:" + count + 4 );


6) What are the values of x and y after the following code has been executed?

int x = 2; int y = -3;int z = 5; if ( x > y + z )y--; x++;

Value of x at this point ______ Value of y at this point ______

int x = 2; int y = -3;int z = 5; if ( x > y + z ) { y--; x++; }

Value of x at this point ______ Value of y at this point ______