Question: 1. What is the difference between counter-controlled repetition and sentinel-controlled repetition? 2. When would you usually use a for loop and when would you usually
1. What is the difference between counter-controlled repetition and sentinel-controlled repetition?
2. When would you usually use a for loop and when would you usually use a while loop?
3. What is wrong with the following code?
int count = 0, num = 1;
while (num < 10)
{
count += num;
}
4. What is the value of num3 after these statements execute?
int num1 = 5;
int num2 = 10;
int num3 = 30;
num3 += num1++ - --num2;
5. What does the following code segment output?
for (int foo = 0; foo <= 10; foo++)
{
if (foo == 2)
continue;
if (foo == 8)
break;
System.out.println(foo);
}
6. Write an application that uses a loop to sum the even numbers from 10 to 100 and displays this value.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
