Given the following four patterns,

Pattern A Pattern B Pattern C Pattern D
1 1 2 3 4 5 6 1 1 2 3 4 5 6
1 2 1 2 3 4 5 2 1 1 2 3 4 5
1 2 3 1 2 3 4 3 2 1 1 2 3 4
1 2 3 4 1 2 3 4 3 2 1 1 2 3
1 2 3 4 5 1 2 5 4 3 2 1 1 2
1 2 3 4 5 6 1 6 5 4 3 2 1 1


Which of the pattern is produced by the following code?
for (int i = 1; i <= 6; i++) {
for (int j = 6; j >= 1; j--)
System.out.print(j <= i ? j + " " : " " + " ");
System.out.println();
}
a. Pattern A
b. Pattern B
c. Pattern C
d. Pattern D

c The outer loop displays a line. The inner loop displays all the numbers in the line. The outer loop is repeated 6 times for i from 1 to 6 . For each i, the inner loops displays i as the first number in the line since j is from 6 to 1 . j is printed for j <= i. Otherwise, a space is printed. Clearly, this code will print Pattern C.

Computer Science & Information Technology

You might also like to view...

________ view allows you to modify the report while seeing the data

Fill in the blank(s) with correct word

Computer Science & Information Technology

Not all presentations contain a master

Indicate whether the statement is true or false

Computer Science & Information Technology