Java Reference
In-Depth Information
18.
What type of loop, such as counter control and sentinel control, will you
use in each of the following situations?
Sum the following series:
1 + (2 / 1) + (3 / 2) + (4 / 3) +
(5 / 4) + ... + (10 / 9)
a.
b.
Sum the following numbers, except the last number:
17
,
32
,
62
,
48
,
58
,
-1
c.
A file contains employees' salaries. Update employees' salaries.
19.
Consider the following
for
loop:
int
j, s;
s = 0;
for
(j = 1; j <= 10; j++)
s = s + j * (j - 1);
In this
for
loop, identify the loop control variable, the initialization
statement, loop condition, the update statement, and the statement that
updates the value of
s
.
20.
Given that the following code is correctly inserted into a program, state its
entire output as to content and form:
num = 0;
5
for
(i = 1; i <= 4; i++)
{
num = num + 10 * (i - 1);
System.out.print(num + " ");
}
System.out.println();
21.
Given that the following code is correctly inserted into a program, describe
the content and form of its entire output:
j = 2;
for
(i = 0; i <= 5; i++)
{
System.out.print(j + " ");
j = 2 * j + 3;
}
System.out.println();
22.
Assume that the following code is correctly inserted into a program:
s = 0;
for
(i = 0; i < 5; i++)
{
s = 2 * s + i;
System.out.print(s + " ");
}
Search WWH ::
Custom Search