Course:: Easy-To-Follow Java Programming
Course:: Easy-To-Follow Java Programming
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
Loop body
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");
a) %@%
@%@
%@%
b) @%@
%@%
@%@
c) %%%
@@@
%%%
d) %@%
%@%
%@%
e) %@%
f) %
@
%
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 ;
3 Loop body
a) for
b) while
c) do-while
d) if
e) else
f) switch
g) Int
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");
a) %@%
@%@
%@%
b) @%@
%@%
@%@
c) %%%
@@@
%%%
d) %@%
%@%
%@%
e) %@%