Q1: What is printed as a result of executing the following code segment?
int count = 0;
for (int x = 0; x < 4; x++) {
for (int y = x; y < 4; y++)
count++;
}
System.out.println(count);
4
8
10
16
20
2.
Q2: What is the minimum number of times “Hello” can be printed?
int k = // a random number such that 1 <= k <= n ;
for (int p = 2; p <= k; p++) {
for (int r = 1; r < k; r++)
System.out.println("Hello");
}
0
1
2
n - 1
n - 2
3.
Q3: What is printed as a result of executing the following code segment?
for (int r = 3; r > 0; r--) {
int c;
for (c = 1; c < r; c++)
System.out.print("-");
for (c = r; c <= 3; c++)
System.out.print("*");
System.out.println();
}
See diagram for answer A
See diagram for answer B
See diagram for answer C
See diagram for answer D
See diagram for answer E
4.
Q4: What is printed as a result of executing the following code segment?