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

1.When will the loop in the following code snippet stop? I. When the user enters

ID: 3680042 • Letter: 1

Question

1.When will the loop in the following code snippet stop?

I. When the user enters an integer

II. When the user enters an alphabetic character

III. After the user enters 100 numbers

Select one:

a. I or II

b. II only

c. III only

d. II or III

2.

How many times does the following loop execute?

Select one:

a. 9 times

b. 8 times

c. 5 times

d. 1 time

3.

Which of the following statements is correct about a sentinel?

Select one:

a. A sentinel is a value that creates a bridge between a data set and unrelated input.

b. A sentinel is a value that is part of the data to be processed by the program.

c. A sentinel is a value that terminates a program.

d. A sentinel is a value that indicates the end of an input sequence.

Explanation / Answer

1. First Question : When will the loop in the following code snippet stop?

Answer: D.

In the below two cases loop will stop.

1) When the user enters an alphabetic character: Because program expects the double value as an input. When you pass character value as an input then program will terminate with an exception "Exception in thread "main" java.util.InputMismatchException". So this case if you pass character instead of double value as an input then loop wll terminate and also program will terminate with an exception said above.

2) After the user enters 100 numbers: After entering 100 double/integer values as an input do-whle loop condition will return false because count value become 100 in that case. So loop will stop.

2. Second Question: How many times does the following loop execute?

Answer: C - 5 times.

First 4 times char value will get lower case so found boolean variable is false. In 5th time, char value will get Uppercase letter so found boolean variable is true. So for loop condition will fail becuase found boolean variable is true. in Condtion !found means false. So after 5 iteration for loop will stop. Thats why asnwer is 5 times.

3. Third Question: Which of the following statements is correct about a sentinel?

Answer: C - A sentinel is a value that terminates a program.

a sentinel value (also referred to as a flag value, trip value, rogue value, signal value, or dummy data) is a special value in the context of an algorithm which uses its presence as a condition of termination, typically in a loop or recursive algorithm.

For Example: