Question: QUESTION 21 Assume that names is an empty ArrayList of String. What will be the contents of names after the following code fragment? names.add(Annie); names.add(Bob);
QUESTION 21
Assume that names is an empty ArrayList of String. What will be the contents of names after the following code fragment?
names.add("Annie");
names.add("Bob");
names.add("Charles");
for (int i = 0; i < 3; i++)
{
String extra = names.get(i);
names.add(extra);
}
| A. | Annie Bob Charles Annie Bob Charles | |
| B. | Annie Bob Charles Charles Bob Annie | |
| C. | Annie Annie Bob Bob Charles Charles | |
| D. | Annie Bob Charles Bob Charles |
QUESTION 22
What is the value of num after the following code fragment?
int num = 3;
num++;
| A. | 2 | |
| B. | 3 | |
| C. | 4 | |
| D. | 5 |
QUESTION 23
What is the value of num after the following code fragment?
int num = 3;
num = num 2 * num;
num++;
| A. | 2 | |
| B. | 0 | |
| C. | 2 | |
| D. | 4 |
QUESTION 24
What are the values of num1 and num2 after the following code fragment?
double num1 = 4.2;
double num2 = num1 * 10 + 5.0;
| A. | num1 is 4.2 and num2 is 63.0 | |
| B. | num1 is 4.2 and num2 is 47.0 | |
| C. | num1 is 42.0 and num2 is 42.0 | |
| D. | num1 is 42.0 and num2 is 47.0 |
QUESTION 25
What is the value of price after the following code fragment?
double price = 30.0;
double discount = 10.0;
price = price - price * (discount / 100.0);
| A. | 30.0 | |
| B. | 20.0 | |
| C. | 27.0 | |
| D. | 33.0 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
