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

The data in an Excel table can only be sorted into ascending order

Indicate whether the statement is true or false

Computer Science & Information Technology

Static member ____ can only access static data members and other static member ____ of the class.

a. functions, functions b. objects, variables c. variables, functions d. references, variables

Computer Science & Information Technology

If an IP address has the number 192 in the first octet, it is a class _______ address

a. A b. B c. C d. D

Computer Science & Information Technology

The Select All button, which selects all controls in a report or group, is located on the ____ tab of the Report Design Tools.

A. Design B. Arrange C. Format D. Page Setup

Computer Science & Information Technology