Quiz On FOR Loops
Quiz On FOR Loops
revised: 09/23/99
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.
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
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 ?
a. int j = 0
b. int j < 0
c. int j = -3
d. int j = -4
C
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
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
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
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
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.)
http://web.cs.iastate.edu/~honavar/JavaNotes/Notes/chap41/chap41quiz.html Page 4 of 4