Chapter 31 JAVA Flashcards
What is the most common operation performed by a program?
A. Adding integer one to an integer variable.
B. Floating point division.
C. Object construction.
D. Internet access.
A. Adding integer one to an integer variable.
What two steps are performed when an assignment statement is executed?
A.
The expression on the right of the “=” is evaluated, “using” all the variables it contains.
The result of evaluation is assigned to the variable on the left of the “=”.
B.
All appropriate variables are incremented or decremented.
The result is assigned to the variable on the left of the “=”.
C.
All appropriate variables are incremented.
All appropriate variables are decremented.
D.
The arithmetic expression is evaluated and assigned to the variable on the left of the “=”.
Variables are auto-incremented or auto-decremented.
A.
The expression on the right of the “=” is evaluated, “using” all the variables it contains.
The result of evaluation is assigned to the variable on the left of the “=”.
What is the meaning of variable++ ?
A. Add one to the variable.
B. Add one to the variable after its current value has been used.
C. Add one to the variable before using its value.
D. Double the value in the variable.
B. Add one to the variable after its current value has been used.
What does the following program output to the monitor:
int value = 0;
int count = 1;
value = ++ count ; /* note change from previous */
System.out.println(“value: “+ value “ + count: “ + count );
A. value: 0 count: 1
B. value: 1 count: 1
C. value: 1 count: 2
D. value: 2 count: 2
D. value: 2 count: 2
What is the output of the following:
int a = 0;
int b = 10;
a = –b ;
System.out.println(“a: “ + a + “ b: “ + b );
A. a: 9 b:11
B. a: 10 b: 9
C. a: 9 b:9
D. a: 0 b:9
C. a: 9 b:9
What is the output of the following program:
double w = 12.5 ;
w *= 2 ;
System.out.println( “ w is “ + w );
A. w is 12.5
B. w is 13.5
C. w is 25.0
D. w is 2
C. w is 25.0
Which of the answers does the same thing as the following:
value += sum++ ;
A.
value = value + sum;
sum = sum + 1;
B.
sum = sum + 1;
value = value + sum;
C.
value = value + sum;
d.
value = value + ++sum;
A.
value = value + sum; sum = sum + 1;
. Fill in the blank so that wages is divided by two.
wages _____ 2 ;
A. *=
B. -=
C. =/
D. /=
D. /=
Are the auto-increment and auto-decrement operators (++ and – ) an essential part of the Java language?
A. No — any program that uses them could be written without them.
B. No — they are not fundamental, but some programs could not be written without them.
C. Yes — some programs can’t be written unless these operators are available.
D. Yes — because adding or subtracting one can’t be done without them.
A. No — any program that uses them could be written without them.
What does the following program output to the monitor:
int value = 0;
int count = 1;
value = count++ ;
System.out.println(“value: “+ value “ + count: “ + count );
A. value: 0 count: 0
B. value: 0 count: 1
C. value: 1 count: 1
D. value: 1 count: 2
D. value: 1 count: 2