Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 21 Assume that names is an empty ArrayList of String. What will be the

ID: 3864235 • Letter: Q

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");

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

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

Explanation / Answer

Note: could you just type the 23 question in the comment please.Because i couldnt find it clear.Thank You

__________

21)Ans)A

names.add("Annie");

names.add("Bob");

names.add("Charles");

After execution of three line Annie Bob Charles is added into the ArrayList.Now the contents of the ArrayList are

Anni Bob Charles

for (int i = 0; i < 3; i++) //Iterating the for loop over the ArrayList

{

   String extra = names.get(i); //Getting each from the ArrayList from the Starting

   names.add(extra); //Adding Each element to the End of the ArrayList

}

So when we display the ArrayList the contents are Annie Bob Cherles Annie Bob Cherles

___________________

22)Ans)C

Reason:

int num = 3; //3 is assigned to the variable num

num++; (Which means num=num+1=3+1=4)

So num value after these statements is 4

_______________

23)

24)Ans)B

Reason:

According to the order of precedence Multiplication having more priority than Addition

num1=4.2;

so num2=(num1*2)+5.0=(4.2*10)+5.0=42.0.10=47.0

______________

25)Ans)C

Reason:

double price = 30.0;

double discount = 10.0;

price = price - price * (discount / 100.0); =// price=30.0 - 30.0 *(10.0/100.0) =30.0 - 30.0( 0.01) =30.0-3.0=27.0

_______________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote