Given the following four patterns,



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. Pattern 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...

In a ring topology, data travels in both directions

Indicate whether the statement is true or false

Computer Science & Information Technology

Approximately 1,000,000 (one million) bytes is a(n) __________

Fill in the blank(s) with correct word

Computer Science & Information Technology