Java Reference
In-Depth Information
39.
Given the following program segment:
for
(number = 1; number <= 10; number++)
System.out.print(number + " ");
System.out.println();
write a
while
loop and a
do
...
while
loop that have the same output.
40.
Given the following program segment:
j = 2;
for
(i = 1; i <= 5; i++)
{
System.out.print(j + " ");
j = j + 5;
5
}
System.out.println();
write a
while
loop and a
do
...
while
loop that have the same output.
41.
What is the output of the following program?
public class
Mystery
{
public static void
main(String[] args)
{
int
x, y, z;
x = 4;
y = 5;
z = y + 6;
do
{
System.out.print(z + " ");
z = z + 7;
}
while
(((z - x) % 4) != 0);
System.out.println();
}
}
42.
To further learn how nested
for
loops work, do a walk-through of the
following program segments and, in each case, determine the exact output.
int
i, j;
a.
for
(i = 1; i <= 5; i++)
{
for
(j = 1; j <= 5; j++)
System.out.printf("%3d", i);
System.out.println();
}
Search WWH ::
Custom Search