Fall-Quiz#4: Iteration, conditionals, order ops Flashcards
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
c
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 )
b
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
c
- double and float are two different names for the same Java data type
- 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
c
which of the following are numeric constants
a. 0.5
b. .50
c. .5
d. 5,000.00
abc
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
d
what is displayed on the screen?
int n = 12, m = 4;
System.out.print( m%(n+1) + n % (m+1) );
1
which of the following is not a relational operator
a. >=
b.
d
which of the following is not a logical operator
a. ==
b. !
c. &&
d. ||
a
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
d