0% found this document useful (0 votes)
53 views4 pages

Quiz On FOR Loops

This document is a 10 question practice quiz on for loops in Java. The quiz covers topics such as the basic structure of for loops, the components of a for loop (initialization, test condition, increment/decrement), and the output of various for loop code snippets.

Uploaded by

Salif Ndiaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Quiz On FOR Loops

This document is a 10 question practice quiz on for loops in Java. The quiz covers topics such as the basic structure of for loops, the components of a for loop (initialization, test condition, increment/decrement), and the output of various for loop code snippets.

Uploaded by

Salif Ndiaye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Quiz on FOR Loops 1/29/17, 10)36 AM

revised: 09/23/99

Quiz on for Loops

This is a practice quiz. The results are not recorded anywhere and do not affect
your grade. The questions on this quiz might not appear in any quiz or test that
does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice
by clicking on its button. You can change your answers at any time. When the quiz
is graded, the correct answers will appear in the box after each question.

1. What are the three general types of looping structures?


a. counting loop, sentinel-controlled loop, and result-controlled loop.
b. infinite loop, counting loop, nested loop
c. while loop, for loop, do loop
d. count up loop, count down loop, infinite loop
A

2. What is the output of the following program fragment?

for ( int j = 0; j < 5; j++ )


{
System.out.print( j + " " );
}
System.out.println( );

a. 0 1 2 3 4 5
b. 0 1 2 3 4
c. 0 1 2 3 4 5
d. j j j j j
B

3. What is the output of the following code fragment?

for ( int j = 10; j > 5; j-- )


{
System.out.print( j + " " );
}
System.out.println( );

http://web.cs.iastate.edu/~honavar/JavaNotes/Notes/chap41/chap41quiz.html Page 1 of 4
Quiz on FOR Loops 1/29/17, 10)36 AM

a. 10 11 12 13 14 15
b. 9 8 7 6 5 4 3 2 1 0
c. 10 9 8 7 6 5
d. 10 9 8 7 6
D

4. What must the test be so that the following fragment prints out the integers 5 through and including 15?
for ( int j = 5; ________ ; j++ )
{
System.out.print( j + " " );
}
System.out.println( );

a. j<15
b. j<=16
c. j<16
d. j==15
C

5. What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10?
for ( int j = 0; j <= 10; _______ )
System.out.print( j + " " );
System.out.println( );

a. j+2
b. j = j+2
c. j++++
d. ++j++
B

6. What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ?

for ( _______; j < 0; j++ )


System.out.print( j + " " );
System.out.println( );

a. int j = 0
b. int j < 0
c. int j = -3
d. int j = -4
C

7. What is the output of the following code fragment?

http://web.cs.iastate.edu/~honavar/JavaNotes/Notes/chap41/chap41quiz.html Page 2 of 4
Quiz on FOR Loops 1/29/17, 10)36 AM

for ( int j = 5; j > -5; j-- )


System.out.print( j + " " );

System.out.println( );

a. -5 -4 -3 -2 -1 0
b. 5 4 3 2 1 0
c. 5 4 3 2 1 0 -1 -2 -3 -4 -5
d. 5 4 3 2 1 0 -1 -2 -3 -4
D

8. What is the output of the following code fragment?


int count = 0;
for ( ; count < 9; ++count )
System.out.print( count + " " );

System.out.println( );

a. 0 1 2 3 4 5 6 7 8
b. Nothing --- the program will not compile.
c. 0 1 2 3 4 5 6 7
d. 1 2 3 4 5 6 7 8 9
A

9. What is the output of the following code fragment?

for ( int count = 0; count < 9; )


System.out.print( count + " " );
count++ ;
System.out.println( );

a. 0 1 2 3 4 5 6 7 8
b. Nothing --- the program will not compile.
c. count count count count count count count count count
d. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
D

10. What is the output of the following code fragment?

int j;
for ( j = 0; j < 5; )
{
System.out.print( j + " " );
j++ ;
}

System.out.println( );

http://web.cs.iastate.edu/~honavar/JavaNotes/Notes/chap41/chap41quiz.html Page 3 of 4
Quiz on FOR Loops 1/29/17, 10)36 AM

a. 0 1 2 3 4
b. Nothing --- the program will not compile.
c. 1 2 3 4 5
d. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
A

grade quiz

The number you got right: 0 Percent Correct: 0 Letter Grade: hmm..

(If you have just returned here from another page, or re-loaded this page, you will need to click again on
each of your choices for the grading program to work.)

Click here to go back to the main menu.

http://web.cs.iastate.edu/~honavar/JavaNotes/Notes/chap41/chap41quiz.html Page 4 of 4

You might also like