Question 1 of 10
A stopwatch club counts ticks. How many times is ticks++ executed?
int ticks = 0;
for (int i = 1; i <= 5; i++) {
ticks++;
}
- A. 4
- B. 5
- C. 6
- D. 1
A stopwatch club counts ticks. How many times is ticks++ executed?
int ticks = 0;
for (int i = 1; i <= 5; i++) {
ticks++;
}
A lap board prints a letter while a counter stays positive. How many times is print("A") executed?
int k = 3;
while (k > 0) {
System.out.print("A");
k--;
}
A starter pistol prints a cue. How many times is print("Go") executed?
for (int i = 0; i < 4; i++) {
System.out.print("Go");
}
Two fragments print a dash. How many more times does Fragment P execute print("-") than Fragment Q?
for (int i = 1; i <= 6; i++) {
System.out.print("-");
}
for (int i = 1; i < 6; i++) {
System.out.print("-");
}
Fragment P is the first loop. Fragment Q is the second loop.
A warehouse stamps nested labels. How many times is c++ executed?
int c = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 4; j++) {
c++;
}
}
A printer marks an outer header and inner items. How many times is print("I") executed?
for (int i = 1; i <= 2; i++) {
System.out.print("O");
for (int j = 1; j <= 3; j++) {
System.out.print("I");
}
}
A triangular stamp count uses an inner bound that depends on the outer variable. How many times is t++ executed?
int t = 0;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
t++;
}
}
Originally the outer loop uses i <= 4 and the inner loop uses j <= 5 around a print(".") statement. If only the outer bound is changed to i <= 6, how many times does print(".") execute?
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 5; j++) {
System.out.print(".");
}
}
Compare the two print statements. How many more times is print("R") executed than print("L")?
for (int a = 0; a < 5; a++) {
System.out.print("L");
for (int b = 0; b < 3; b++) {
System.out.print("R");
}
}
Fragment P and Fragment Q each increment x. Which statement is true?
int x = 0;
for (int i = 1; i <= 10; i++) {
x++;
}
int y = 0;
int i = 1;
while (i <= 10) {
y++;
i += 2;
}
Fragment P is the for loop. Fragment Q is the while loop.