You are on page 1of 2

Practice Loop Questions

What is wrong the following program segment?


int x= 1;
while (x < 10)
System.out.println(x);
What is wrong the following program segment?
int x;
while (x < 10)
{
x++;
System.out.println(x);
}
What is wrong the following program segment?
int x = 4;
int y = 4;
while (x = y)
{
x++;
System.out.println(x);
}
What is the output of the following program segment?
int x = 0, count = 0;
for(x= 10; x < 10; x++)
count++;
System.out.println(count);
How many times will the body of the following loop be executed?
for(int x= 0; x < 9; x++)
x++;
How many times will the body of the following loop be executed?
for(int x= 0; x < 9; x++)
System.out.println(x);
What is the output of the following program segment?
int x;
x=66;
while (x>3)
{
System.out.print(x + );
x/=3;
}

What are the first and last numbers printed by the following program segment?
for (int x = 0; x <= 987654; x++)
System.out.print((x+1) + );
How do I include more than 1 program statement in the body of a loop?
If you know you want to repeat a process exactly 10 times, what loop structure would
you use?
If you know you want to repeat a process until a user enters the value integer 999, what
loop structure would you use?
What is a conditional expression?
I am answering multiple choice questions dealing with loops. Each question includes the
code for the loop. The answers show possible printed output from the loops. What
strategies might I use to eliminate possible answers?
Does indentation affect the execution of a loop?

You might also like