Question 1 of 10
A cafeteria line numbers trays from 2 through 8 inclusive. How many times is c++ executed?
int n = 2;
int c = 0;
while (n <= 8) {
c++;
n++;
}
- A. 6
- B. 8
- C. 7
- D. 9
A cafeteria line numbers trays from 2 through 8 inclusive. How many times is c++ executed?
int n = 2;
int c = 0;
while (n <= 8) {
c++;
n++;
}
An usher counts seats with a loop that includes both endpoints. How many times is print("S") executed?
for (int i = 0; i <= 6; i++) {
System.out.print("S");
}
Fragment G uses i < 5. Fragment H uses i <= 5. Both start i at 1 and print once per pass. How many more times does Fragment H execute print("*") than Fragment G?
for (int i = 1; i < 5; i++) {
System.out.print("*");
}
for (int i = 1; i <= 5; i++) {
System.out.print("*");
}
A mailroom nested loop stamps every inner slot. How many times is print("@") executed?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 5; j++) {
System.out.print("@");
}
}
How many times is print("B") executed?
for (int i = 1; i <= 3; i++) {
System.out.print("A");
for (int j = 1; j <= 4; j++) {
System.out.print("B");
}
}
A square of marks uses matching bounds. How many times is print("*") executed?
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
System.out.print("*");
}
}
A triangular count uses j <= i with i running from 1 through 6. How many times is n++ executed?
int n = 0;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= i; j++) {
n++;
}
}
A mixed nested loop resets the inner index on every outer pass. How many times is c++ executed?
int c = 0;
for (int i = 1; i <= 3; i++) {
int j = 0;
while (j < 5) {
c++;
j++;
}
}
A kiln controller skips values by adding 3. How many times is print("T") executed?
for (int i = 0; i < 20; i += 3) {
System.out.print("T");
}
After both loops finish, what text does this Java code display?
int p = 0;
int q = 0;
for (int i = 1; i <= 4; i++) {
p++;
for (int j = 1; j <= 5; j++) {
q++;
}
}
System.out.print(p);
System.out.print(" ");
System.out.print(q);