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

________ restores your computer's system files to an earlier point in time

Fill in the blank(s) with correct word

Computer Science & Information Technology

Describing the text that appears on a Web page is done using ____________________ elements.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

While designing websites for mobile devices, _____ colors should be used so that pages are easily visible in outdoor lighting.?

A. ?contrasting B. ?red and blue C. ?darker D. ?lighter

Computer Science & Information Technology

A ________ connects two or more computers in a network.

A) repeater B) hub C) router D) switch

Computer Science & Information Technology