Sunday 20 December 2020

Pattern 8, 9, 10 and 11

public class p3 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)
		{
			for(int j=1; j<=5;j++)
			{
				if(i==j)
					System.out.print("1 ");
				else
					System.out.print("0 ");
			}
		System.out.println();
		}
	}
}
OUTPUT

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

public class p5 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)
		{
			for(int j=1; j<=5;j++)
			{
				if(i<=j)
					System.out.print("1 ");
				else
					System.out.print("0 ");
			}
		System.out.println();
		}
	}
}
OUTPUT

1 1 1 1 1 
0 1 1 1 1 
0 0 1 1 1 
0 0 0 1 1 
0 0 0 0 1 
public class p6 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)
		{
			for(int j=1; j<=5;j++)
			{
				if(j<=i)
					System.out.print("1 ");
				else
					System.out.print("0 ");
			}
		System.out.println();
		}
	}
}

OUTPUT

1 0 0 0 0 
1 1 0 0 0 
1 1 1 0 0 
1 1 1 1 0 
1 1 1 1 1 
public class p7 {
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)
		{
			for(int j=1; j<=5;j++)
			{
				if(i==j)
					System.out.print("* ");
				else if(i<j)
					System.out.print("1 ");
				else
					System.out.print("o ");
			}
		System.out.println();
		}
	}
}

OUTPUT

* 1 1 1 1 
o * 1 1 1 
o o * 1 1 
o o o * 1 
o o o o * 
Pattern 1 & 2

No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32