Pattern programs

Pattern

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

Program


package com.wordpress.sreeharshasite;
import java.util.Scanner;
public class PatternB {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of rows");
int rows=sc.nextInt();
for(int i=1;i<=rows;i++)
{
for(int j=1;j<=i;j++)
{
if(j%2==1)
System.out.print(1+" ");
else
System.out.print(0+" ");
}
System.out.println();
}
sc.close();
}
}

Output

Enter the number of rows
10
1 
1 0 
1 0 1 
1 0 1 0 
1 0 1 0 1 
1 0 1 0 1 0 
1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 
1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0

 

 

Advertisements

I am Sreeharsha from Bengaluru. I am working in java for the past 6+ years. In this blog i will be sharing posts regarding java , advanced java , monthly challenges, collection of quotes , my themes and many more. If you like my posts please follow my blog.

Tagged with: ,
Posted in Core Java, Pattern programs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow My Diary on WordPress.com
Archives

Enter your email address to follow this blog and receive notifications of new posts by email.

%d bloggers like this: