0% found this document useful (0 votes)
38 views

Course:: Easy-To-Follow Java Programming

1. The document contains a quiz with multiple choice questions about Java loops. 2. The questions cover the order of parts in while, do-while and for loops, and which commands break and continue are used with. 3. The answers to the questions are provided after the questions.

Uploaded by

Fuad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Course:: Easy-To-Follow Java Programming

1. The document contains a quiz with multiple choice questions about Java loops. 2. The questions cover the order of parts in while, do-while and for loops, and which commands break and continue are used with. 3. The answers to the questions are provided after the questions.

Uploaded by

Fuad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Course: Easy-to-follow Java programming

The quiz questions


Answer the questions below to review what you have learned in Video 2. You will
find the right answers after the questions in the solution part.

1. Put the different parts of the while loop into the right order.

product *= number;
number++;

) {

while

number < 9

2. Put the different parts of the do-while loop into the right order.

number < 9

product *= number;
number++;

while

do

Duckademy IT courses – www.duckademy.com


3. In what order do the different parts of the for loop run?
(The question is not in what order do we put the different parts into the heading
of the for loop, but in what order will they run.)

Loop body

Initialization part (e.g. int i = 0)

Increment part (e.g. i++)

Condition part (e.g. i < 10)

4. With which commands do we use break together?

a) for
b) while
c) do-while
d) if
e) else
f) switch
g) Int

5. Which command will the program execute after continue? What is the
number of the comment before that command?

int i;
/*1*/ System.out.println("before loop");
for (/*2*/ i = 1; /*3*/ i <= 5; /*4*/ i++) {
/*5*/ System.out.println("before");
if (i == 3) {
continue;
}
/*6*/System.out.println("after");
}
/*7*/System.out.println("at the end");

Duckademy IT courses – www.duckademy.com


6. What will the following program print?

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
if ((i+j) % 2 == 0) {
System.out.print("%");
} else {
System.out.print("@");
}
}
System.out.println();
}

a) %@%
@%@
%@%
b) @%@
%@%
@%@
c) %%%
@@@
%%%
d) %@%
%@%
%@%
e) %@%
f) %
@
%

Duckademy IT courses – www.duckademy.com


----------------------------------------------------------------------------------------------------------------

The answers

1. Put the different parts of the while loop into the right order.

5 product *= number;
number++;

4 ) {

2 (

1 while

3 number < 9

6 }

while
(
number < 9
) {
product *= number;
number ++;
}

2. Put the different parts of the do-while loop into the right command.

7 number < 9

3 product *= number;
number++;

4 }

2 {

5 while

6 (

1 do

8 )

9 ;

Duckademy IT courses – www.duckademy.com


do
{
product *= number;
number++;
}
while
(
number < 9
)
;

3. In what order do the different parts of the for loop run?


(The question is not in what order do we put the different parts into the heading
of the for loop, but in what order will they run.)

3 Loop body

1 Initialization part (e.g. int i = 0)

4 Increment part (e.g. i++)

2 Condition part (e.g. i < 10)

4. With which commands do we use break together?

a) for
b) while
c) do-while
d) if
e) else
f) switch
g) Int

Duckademy IT courses – www.duckademy.com


5. Which command will the program execute after continue? What is the
number of the comment before that command?

int i;
/*1*/ System.out.println("before loop");
for (/*2*/ i = 1; /*3*/ i <= 5; /*4*/ i++) {
/*5*/ System.out.println("before");
if (i == 3) {
continue;
}
/*6*/System.out.println("after");
}
/*7*/System.out.println("at the end");

6. What will the following program print?

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
if ((i+j) % 2 == 0) {
System.out.print("%");
} else {
System.out.print("@");
}
}
System.out.println();
}

a) %@%
@%@
%@%
b) @%@
%@%
@%@
c) %%%
@@@
%%%
d) %@%
%@%
%@%
e) %@%

Duckademy IT courses – www.duckademy.com


f) %
@
%

Duckademy IT courses – www.duckademy.com

You might also like