Java Reference
In-Depth Information
Sequence
Expression
a.
2,4,6,8,10,12,...
b. 4, 19, 34, 49, 64, 79,
...
c. 30, 20, 10, 0,
10,
20,...
d.
3, 1, 5, 9, 13,
...
e. 97, 94, 91, 88, 85, 82,
...
7,
15.
Complete the code for the following
for
loop:
for (int i = 1; i <= 6; i++) {
// your code here
}
so that it prints the following numbers, one per line:
-4
14
32
50
68
86
16.
What is the output of the following
oddStuff
method?
public static void oddStuff() {
int number = 4;
for (int count = 1; count <= number; count++) {
System.out.println(number);
number = number / 2;
}
}
17.
What is the output of the following loop?
int total = 25;
for (int number = 1; number <= (total / 2); number++) {
total = total - number;
System.out.println(total + " " + number);
}
18.
What is the output of the following loop?
System.out.println("+---+");
for (int i = 1; i <= 3; i++) {
System.out.println("\\ /");
System.out.println("/ \\");
}
System.out.println("+---+");
Search WWH ::
Custom Search