How many times will the following loop execute?
for (int i = 0; i < 10; i += 3) {
System.out.println(i);
}
AP (Advanced Placement) · AP Computer Science A
Algorithms with Selection and Repetition: Practice Questions
5 multiple-choice questions marked as you go, and 1 written questions with worked solutions. All on Algorithms with Selection and Repetition.
Given that a, b, and c are boolean variables, which of the following expressions will always evaluate to the same value as (a && b) || (a && c)?
A student is writing a program to find the largest power of 2 that is less than or equal to a positive integer n. Which of the following code segments correctly computes this value and stores it in ans?
Which of the following logical expressions is equivalent to the expression !(a || b) according to De Morgan's Laws?
What is the output of the following code segment?
int count = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j < 3; j++) {
count++;
}
}
System.out.println(count);
A program is designed to analyze a sequence of integers entered by a user until the user enters -1.
Part a: Using a while loop, write a logic flow that calculates the sum of all positive even integers entered.
Part b: Integrate an if-else structure to track the maximum value among the entered positive integers.
Part c: If the user enters the sequence: 4, 7, 2, 10, -1, determine the final values of the sum and the maximum. Show the state of these variables after each iteration.
Write your answer out first, then check it against the worked solution.
* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.
You've seen the model answer. Now get yours marked.
This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.
Want more questions like these? Get a fresh set on this topic, graded as you go.
Practice More