57.5k views
2 votes
Please help me :)

Consider the program segment below. Assume k is a positive number.

for (int i = 2; i <= k; i++)
if (nums[i] < someValue)
System.out.println("FOUND");
What is the maximum number of times FOUND can be printed?

Group of answer choices

k - 1

1

0

k

k - 2

User Gerasalus
by
4.6k points

1 Answer

6 votes

Answer:

k - 1 times

Step-by-step explanation:

Given

The attached code snipped

Required

Maximum number of times, the print statement is executed

From the iteration, we have: i = 2; i<=k; i++

This means that; i = 2 to k

Say:
k = 5


i = 2, 3,4,5 (4 values) i.e. 5 - 1

Say
k = 10


i = 2,3,4,5,6,7,8,9,10 (9 values) i.e. 10 - 1

So, the maximum number of times is k - 1

User Baarkerlounger
by
3.8k points