Showing posts with label Pattern. Show all posts
Showing posts with label Pattern. Show all posts

Wednesday, 30 December 2020

Pattern 1, 2, 3 and 4

public class p10 
{
	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
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}

OUTPUT

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

OUTPUT

* * * * * 
* * * *   
* * *     
* *       
*         
public class P28 
{
	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
					System.out.print("  ");
			}
		System.out.println();
		}
	}
}

OUTPUT

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

OUTPUT

        * 
      * * 
    * * * 
  * * * * 
* * * * *

Pattern 25, 26, 27, 28, 29 and 30

public class P22 
{
	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 4 3 2 1 
  4 3 2 1 
    3 2 1 
      2 1 
        1 

public class p11 
{
	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 1 1 1 1 
  2 2 2 2 
    3 3 3 
      4 4 
        5 

public class p12 
{
	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 2 3 4 5 
  2 3 4 5 
    3 4 5 
      4 5 
        5 

public class p17 
{
	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 B C D E 
  B C D E 
    C D E 
      D E 
        E 
public class P21 
{
	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 5 5 5 5 
  4 4 4 4 
    3 3 3 
      2 2 
        1 

public class p18 
{
	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 A A A A 
  B B B B 
    C C C 
      D D 
        E 

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 

Thursday, 24 December 2020

Pattern 12 & 13

import java.util.*;
public class p8 {
	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		System.out.println("Enter How many rows you want?");
		int n=s.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			for(int j=1; j<=n-i;j++)
			{
				System.out.print(" ");
			}	
			for(int j=1; j<=2*i-1;j++)
			{
				if(i%2==0 && (j==1||j==(i*2-1)))
					System.out.print("+");
				else
					System.out.print("*");
			}
		System.out.println();
		}
	}
}

OUTPUT
       *
      +*+
     *****
    +*****+
   *********
  +*********+
 *************
+*************+


import java.util.*;
public class p9 {
	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		System.out.println("Enter How many rows you want?");
		int n=s.nextInt();
		
		for(int i=n; i>0; i--)
		{
			for(int j=1; j	<=n-i;j++)
			{
				System.out.print(" ");
			}	
			for(int j=1; j	<=2*i-1;j++)
			{
				if(i%2==0&&(j==1||j==(i*2-1)))
					System.out.print("+");
				else
					System.out.print("*");
			}
		System.out.println();
		}
	}
}

OUTPUT

*************
 +*********+
  *********
   +*****+
    *****
     +*+
      *

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

Pattern 5, 6 and 7

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

OUTPUT

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

OUTPUT

1  1  1  1  1  
2  2  2  2  2  
3  3  3  3  3  
4  4  4  4  4  
5  5  5  5  5  
public class p4 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)
		{
			for(int j=1; j<=5;j++)
			{
				System.out.print(j+"  ");
			}
		System.out.println();
		}
	}
}

OUTPUT

1  2  3  4  5  
1  2  3  4  5  
1  2  3  4  5  
1  2  3  4  5  
1  2  3  4  5

Thursday, 17 December 2020

Pattern 23 and 24

public class P23 {
	public static void main(String[] args) 
	{
		for(int i=1; i<6; i++)
		{
			for(int j=i; j<6; j++)
			{
				System.out.print(j + " ");
			}
			for(int k=1; k<i; k++)
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}	
}

OUTPUT

1 2 3 4 5 
2 3 4 5 1 
3 4 5 1 2 
4 5 1 2 3 
5 1 2 3 4 
public class P24 
{
	public static void main(String[] args) 
	{
		for(int i=5; i>0; i--)
		{
			for(int j=i; j<6; j++)
			{
				System.out.print(j + " ");
			}
			for(int k=1; k<i; k++)
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

OUTPUT

5 1 2 3 4 
4 5 1 2 3 
3 4 5 1 2 
2 3 4 5 1 
1 2 3 4 5 

Pattern 31 & 32