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

A java quiz focusing on operator precedence and valid identifiers. It includes instructions for the quiz, an operator precedence table, and several java code snippets to evaluate. Students are required to identify invalid java identifiers and evaluate given expressions using the provided operator precedence table.

Typology: Exercises

2012/2013

Uploaded on 04/07/2013

shabi_564
shabi_564 🇮🇳

4.5

(13)

188 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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 ______