English

Write the program to display the following pattern: 11 01 0 11 0 1 01 0 1 0 1 - Computer Applications

Advertisements
Advertisements

Question

Write the program to display the following pattern:

1
1     0
1     0     1
1     0     1     0
1     0     1     0     1

Answer in Brief

Solution

public class Q9d
{ public static void main(String ar[])
{System.out.printIn("\n-----------------");
int i, j;
for (i = 1; i <= 5; i++)
{System.out.printIn();
for (j = 1; j <= i; j++)
{ if (j % 2 != 0)
System.out.print("1" + " "):
else
System.out.print("0" + " ");
}}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 1.1: Nested Loop - EXERCISES [Page 146]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.1 Nested Loop
EXERCISES | Q VI. 9. (d) | Page 146
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×