Implementing Selection and Iteration Algorithms FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

Contract: Input.readInt() reads the next integer the user types and returns it as int. Each call consumes one integer. Remembering Scanner method names is not required. A choir groups singers in threes.

(a) Write Java that stores the next typed integer in n, then prints trio if n is divisible by 3 and other otherwise. (b) If the user types 15, state the displayed text. (c) Give the remainder 15 % 3 and explain how it selects the printed word.

Question 2 of 5

A meter peels digits of 904 from right to left.

(a) Write a while loop that prints each digit of 904 starting from the ones place using % 10 and /= 10. (b) State the displayed text. (c) Explain why n /= 10 is required for the loop to finish.

Question 3 of 5

Contract: Input.readInt() reads the next integer the user types and returns it as int. Each call consumes one integer. Remembering Scanner method names is not required. Five readings are typed in this order: 11, 8, 4, 7, 10.

(a) Write a loop that counts how many of those five values are even and stores the count in evenHits. (b) State the final value of evenHits. (c) Explain how % 2 decides whether a reading is counted.

Question 4 of 5

Contract: Input.readInt() reads the next integer the user types and returns it as int. Each call consumes one integer. Remembering Scanner method names is not required. Four crate masses are typed in this order: 14, 9, 21, 9.

(a) Write Java that stores the smallest of those four values in an int named least. (b) State the final value of least. (c) Explain what happens when a later value equals the current least.

Question 5 of 5

The integers 1 through 6 are summed, then averaged with int division.

(a) Write a loop that stores the sum in total and the count in terms, then prints total / terms. (b) State the sum and the printed result. (c) Explain why the printed result is 3 rather than 3.5.