Fall-Quiz#4: Iteration, conditionals, order ops Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what is the result when the following code segment is executed?

int m = 4; n= 5;
double d = Math.sqrt( (m + n) / 2);
System.out.print(d)

a. syntax error “sqrt(double) in java.lang.Math cannot be applied to int”
b. 1.5 is displayed
c. 2.0 is displayed
d. 2.1213 is displayed
e. ClassCastException

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

given that x is true, and z is false, which of the following expressions will evaluate to false?

a. ( x && y ) || z
b. ( x || y ) && z
c. y || ( x && z )
d. x || ( y && z )
e. x && ( y || z )

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the scope of a variable

a. the range of values that the variable can assume (take on)
b. the number of bytes the variable occupies in memory
c. the places in the code where the variable is “visible” and can be referred to
d. the period of time from the point the variables is initialized in the program to the point when it is destroyed

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. double and float are two different names for the same Java data type
  2. char, float, int, and boolean are all primitive data types

a. neither are true
b. 1 is true only
c. 2 is true only
d. both 1 and 2 are true

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

which of the following are numeric constants

a. 0.5
b. .50
c. .5
d. 5,000.00

A

abc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

suppose your program needs to convert inches into centimeters. which of the following is a valid reason for using a symbolic constant double CM_PER_INCH = 2.54 for the conversion factor rather than the literal constant 2.54

a. self documenting code
b. better precision in calculations
c. faster compilation
d. easier program maintenance

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is displayed on the screen?

int n = 12, m = 4;
System.out.print( m%(n+1) + n % (m+1) );

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

which of the following is not a relational operator
a. >=
b.

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

which of the following is not a logical operator

a. ==
b. !
c. &&
d. ||

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does “short circuit evaluation” mean for the || operator

a. if the right operand evaluates to false, the left operand is not evaluated
b. if the right operand evaluates to true, the left operand is not evaluated
c. if the left operand evaluates to false, the right operand is not evaluated
d. if the left operand evaluates to true, the right operand is not evaluated

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly