Primitive Data Types - Computer Science - Quiz, Exercises of Computer Science

Main points of this past exam are: Output is Produced, Unix Command, Working Directory, Html File, Correctly Written, Java Class, Produce a File

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 2009 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 not valid Java identifiers? (Circle your answer(s).)
this&that thisRthat This2That integer
This-That this_R_that 2_This_That this1+that1
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 || exp2 && exp1;
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) In general, you should define instance variables to be (Circle the letter of the correct answer):
A. public
B. private
C. primitive data types
D. reference data types (Continued on other side)
pf2

Partial preview of the text

Download Primitive Data Types - Computer Science - Quiz and more Exercises Computer Science in PDF only on Docsity!

Signature _____________________ CSE 11 Name ________________________

Quiz 1

cs11f ____ Fall 2009 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 not valid Java identifiers? (Circle your answer(s).)

this&that thisRthat This2That integer

This-That this_R_that 2_This_That this1+that

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 || exp2 && exp1; 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) In general, you should define instance variables to be (Circle the letter of the correct answer):

A. public

B. private

C. primitive data types

D. reference data types

(Continued on other side)

4) Which of the following Java constructs would most likely be considered a mutator? (Circle correct letter)

A. canvas.getWidth()

B. sun = new FilledOval( 50, 150, 100, 100, canvas )

C. greeting.setText( "Hello" )

D. sun.moveTo( 50, 150 )

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

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

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 "D"?

int a = ______ ;

int b = ______ ;

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