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

A java quiz focusing on operator precedence and valid java identifiers. The quiz includes multiple-choice questions and programming exercises. Students are required to evaluate java expressions using the given operator precedence table and determine the value of variables based on given conditions.

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 2010 Student ID ____________________
This quiz is to be taken by yourself with closed books, closed notes, no calculators.
(Partial) Operator Precedence Table
Operators Associativity
! ++ -- (pre & post inc/dec) right to left
* / % 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 valid Java identifiers? (Circle your answer(s).)
this&that _thisRthat This_2_That boolean
_9_2_5 n!ne_2_5 9_2_5 bool
2. Using the operator precedence table above, evaluate each expression and state what gets printed. Remember
short-circuit evaluation with && and ||.
int a = 5;
int b = -2;
int c = 2;
boolean exp1 = a + b * c <= a + c * b; _________ (value of exp1)
boolean exp2 = !(c + a > b); _________ (value of exp2)
boolean exp3 = b - a >= c; _________ (value of exp3)
boolean z = exp1 && exp2 || exp3;
System.out.print( "z = " + z ); ____________________
z = exp3 || exp1 && !exp2;
System.out.print( "z = " + z ); ____________________
b = --b + ++a % 4 * c++ * 2;
System.out.print( "a = " + a ); ____________________
System.out.print( "b = " + b ); ____________________
System.out.print( "c = " + c ); ____________________
3. Where is the coordinate (0,0) in a graphics window? (Circle correct letter.)
A. at the center of the window
B. at the upper right corner of the window
C. at the upper left corner of the window
D. at the bottom right corner of the window
E. at the bottom left corner of the window (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 2010 Student ID ____________________

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

(Partial) Operator Precedence Table

Operators Associativity

! ++ -- (pre & post inc/dec) right to left

* / % 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 valid Java identifiers? (Circle your answer(s).)

this&that _thisRthat This_2_That boolean

_9_2_5 n!ne_2_5 9_2_5 bool

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

short-circuit evaluation with && and ||.

int a = 5; int b = -2; int c = 2;

boolean exp1 = a + b * c <= a + c * b; _________ (value of exp1)

boolean exp2 = !(c + a > b); _________ (value of exp2)

boolean exp3 = b - a >= c; _________ (value of exp3)

boolean z = exp1 && exp2 || exp3; System.out.print( "z = " + z ); ____________________ z = exp3 || exp1 && !exp2; System.out.print( "z = " + z ); ____________________

b = --b + ++a % 4 * c++ * 2; System.out.print( "a = " + a ); ____________________ System.out.print( "b = " + b ); ____________________ System.out.print( "c = " + c ); ____________________

3. Where is the coordinate (0,0) in a graphics window? (Circle correct letter.)

A. at the center of the window

B. at the upper right corner of the window

C. at the upper left corner of the window

D. at the bottom right corner of the window

E. at the bottom left corner of the window (Continued on other side)

4. The naming convention for a class or interface name is (Circle correct letter)

A. start with uppercase, rest mixed

B. start with lowercase, rest mixed

C. all lowercase letters with underscores

D. all uppercase letters with underscores

5. What gets printed with each of the following statements?

int a = 2; int b = 4; int c = 6;

System.out.println( (a + b) + c + " = " + a + (b + c) );

______________________________________

System.out.println( a + (b + c) + " = " + (a + b) + c );

______________________________________

System.out.println( (a + b + c) + " = " + a + b + c );

______________________________________

6. What values of a and b would result in the following code printing "C"?

int a = ______ ;

int b = ______ ;

if ( (a > 1) || (b < -1) ) { if ( a > b ) { System.out.println( "A" ); } else { System.out.println( "B" ); } } else if ( (a == 1) && (b <= -1) ) { System.out.println( "C" ); } else { System.out.println( "D" ); }

7. What is the symbol '!' affectionately known as in computer lingo?

______________________________________