Cs2e Midterm
Cs2e Midterm
1. In a__________Joop, the loop condition is evaluated after executing the body of the loop
2. Executing a________ statement in the body of a loop immediately terminates the loop
3.The________ is called the body of the loop.
4. A_________statement allows a variable to be tested for equality against a list of values.
5. A__________ is a repetition control structure that allows you to efficiently write a loop that needs to
execute a specific number of times.
1. In a do-while loop, the loop condition is evaluated after executing the body of the loop.
2. Executing a break statement in the body of a loop immediately terminates the loop.
3. The block is called the body of the loop.
4. A switch statement allows a variable to be tested for equality against a list of values.
5. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to
execute a specific number of times.
int i = 0, value = 0;
do {
if (i % 2 == 0 && i <= 10)
value += 1 * 1;
else if (i % 2 == 0 && i > 10)
value += i;
else
value -= i;
i++;
} while (i <= 20);
System.out.println("value=" + value);
2. Write a program in Java where a user must enter two integers. The program should then print the two
numbers in ascending order. (20 points)
3. How is a do while loop different from a while loop? (10 points)