Read Section 3.10 in Chapter 3 and Sections 4.1-4.3 in Chapter 4 in the textbook, and then answer the following questions.
int i = 0, j = 0;
while (i < 6) {
j = j + i;
i = i + 1;
}
System.out.println(j);
int i = 0, j = 10;
while (i <= j) {
if (i % 2 == 0) {
System.out.println(i);
}
i = i + 1;
}
int i = 11;
while (i > 0) {
int j = 2;
while (j <= i) {
System.out.print(j + " ");
j = j + 2;
}
i = i - 3;
System.out.println();
}
int n = 4;
while (n != 1) {
System.out.print(n + " ");
if (n % 3 != 0) {
n = 2 * n + 1;
}
else {
n = n / 3;
}
}
int pos = 0;
String a = "camera", b = "computer";
while (pos < a.length()) {
if (a.charAt(pos) == b.charAt(pos)) {
System.out.print(b.charAt(pos));
}
pos = pos + 1;
}
2
13
-7
21
-11
0
The code will read in all the integers, and produce the
following output:
Number of non-zero integers: 5
2
13
-7
21
-11
0
The code will read in all the integers, and produce the
following output:
Number of even integers: 1
Number of odd integers: 4
2
9
-7
4
-3
0
The code will read in all the integers, and produce the
following output:
2
4
3
3
2
***** **** *** ** *