Wednesday, 30 December 2020

Pattern 14, 15, 16, 17, 18 and 19

public class p14
{
	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(j+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
1         
1 2       
1 2 3     
1 2 3 4   
1 2 3 4 5 
public class p15 
{
	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(i+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
1         
2 2       
3 3 3     
4 4 4 4   
5 5 5 5 5 
public class p16 
{
	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((char)(64+j)+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
A         
A B       
A B C     
A B C D   
A B C D E 
public class P17 
{
	public static void main(String[] args) 
	{
		for(int i=5; i>0; i--)
		{
			for(int j=5; j>0;j--)
			{
				if(i<=j)
					System.out.print(i+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
5         
4 4       
3 3 3     
2 2 2 2   
1 1 1 1 1 
public class P18 
{
	public static void main(String[] args) 
	{
		for(int i=5; i>0; i--)
		{
			for(int j=5; j>0;j--)
			{
				if(i<=j)
					System.out.print(j+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
5         
5 4       
5 4 3     
5 4 3 2   
5 4 3 2 1 
public class p16 
{
	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((char)(64+i)+" ");
				else
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}
OUTPUT
A         
B B       
C C C     
D D D D   
E E E E E 

No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32