Given a limit the task is to generate the below given pattern.
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
Where limit = 5
Java
import java.util.*;
public class PatternV4
{
public static void main(String args[])
{
int n=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a limit: ");
n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if(i%2==0)
{
if(j%2==0)
{
System.out.print("1 ");
}
else
{
System.out.print("0 ");
}
}
else
{
if(j%2==0)
{
System.out.print("0 ");
}
else
{
System.out.print("1 ");
}
}
}
System.out.println();
}
}
}Java