Computer Science › Counting Statement Executions
public void countStatements() {
int a = 10, b = 15, c = 7;
// Start
for(int i = 0; i < a; i += 2) {
b--;
System.out.print("*");
}
for(int i = b; i >=0; i--) {
for(int j = 0; j < c; j++) {
System.out.print("*");
}
}
// End
}
In the code above, how many times will System.out.print
be called between the comments "// Start
" and "// End
"?
public void countStatements() {
int[] array = new int[54];
for(int i = 0; i < array.length; i++) {
array[i] = 3 * i + 1;
System.out.println("Yay!");
}
for(int i = 0; i < array[5]; i++) {
array[i]--;
System.out.println("Yay!");
}
for(int i = array[3]; i > 0; i--) {
System.out.println("Yay!");
}
}
How many calls will be made to System.out.println
in the code above?
How many statements are executed in the code snippet below?
for (int i = 0; i < arr.length; i++) {
if (i == 2) {
i++;
}
}