Pattern program2

package patterns1;

public class Pattern_program1 {
public static void main(String[] args) {
	Pattern_program1 pb = new Pattern_program1();
	//pb.simple();
	//pb.simple1();
	//pb.simple2();
	//pb.simple3();
	//pb.simple4();
	//pb.alphabet();
	//pb.alphabet1();
	//pb.pattern1();
	//pb.pattern2();
	//pb.pattern3();
	//pb.pattern4();
	//pb.pattern5();
	//pb.pattern6();
	//pb.pattern7();
	//pb.pattern8();
	//pb.pattern9();
	//pb.pattern10();
	//pb.pattern11();
	//pb.pattern12();
	//pb.pattern13();
	//pb.pattern14();
	//pb.pattern15();
	//pb.pattern16();
	//pb.pattern17();
	//pb.pattern18();
	//pb.pattern19();
	//pb.pattern20();
	//pb.pattern21();
	//pb.pattern22();
	//pb.pattern23();
	//pb.pattern24();
	//pb.pattern25();
	//pb.pattern26();
	pb.pattern27();
	
	
	
}

private void pattern27() {
	// TODO Auto-generated method stub
	
	//***** 
	// *  * 
	//  * * 
	//   ** 
	//    *
	
	for (int i=5; i>= 1 ; i--) {
		for (int j = i; j < 5 ; j++) {
            System.out.print(" ");
        }  
		for (int k = 1; k <= i ;k++) {
            if( k==1 || i == 5 || k==i) {
                System.out.print("*");
            }
            else {
                System.out.print(" ");
            }
	}
		System.out.println(" ");
		}
}

private void pattern26() {
	// TODO Auto-generated method stub
	
	//***** 
	//*  * 
	//* * 
	//** 
	//* 
	
	for (int i=5; i>= 1 ; i--) {
		
		for (int k = 1; k <= i ;k++) {
            if( k==1 || i == 5 || k==i) {
                System.out.print("*");
            }
            else {
                System.out.print(" ");
            }
	}
		System.out.println(" ");
		}
	
}

private void pattern25() {
	// TODO Auto-generated method stub
	
	//********* //3rd for- in 1st (*) condition is k=1,2nd (*) upto 9th (*) condition is i ==5. 
	// *     * //1st space created by 2nd for,then (*)is created by 3rd for-1st (*) by k==1,condition fail (if)condition then i==5.in finally we get last (*)k<=7. 
	//  *   * 
	//   * * 
	//    * 
	
	for (int i=5; i>= 1 ; i--)
    {
        for (int j = i; j < 5 ; j++) {
            System.out.print(" ");
        }   
        for (int k = 1; k <= (2*i -1) ;k++) {
            if( k==1 || i == 5 || k==(2*i-1)) {
                System.out.print("*");
            }
            else {
                System.out.print(" ");
            }
        }
        System.out.println(" ");
    }
	  
}

private void pattern24() {
	// TODO Auto-generated method stub
	
	//* * * * * 
	//  * * * * 
	//    * * * 
	//      * * 
	//        * 
	//      * * 
	//    * * * 
	//  * * * * 
	//* * * * * 

	
	for(int row = 1; row<=5; row++)
	  {
		for(int col=2;col<=row;col++)//assign col=2 because in the 1st line ,we not have space.so it start from 2,it takes2<=2 the condition is true.so it created the space.
		  {
		    System.out.print(" " +" ");
		  }
	  for(int col = 5; col>=row; col--)
	   { System.out.print("*"+" ");
	   }
	  
	  System.out.println();
	  }
	for(int row = 2; row<=5; row++)
	  {
		for(int col=4;col>=row;col--)//assign col=4 because in the 1st line of second half, we want 3 space in that 4>=2 condition true.so it executed space .A following that way until 2>=2 it executed,1>=2 condition is false then loop stopped.
		  {
		    System.out.print(" " +" ");
		  }
	  for(int col = 1; col<=row; col++)
	   { System.out.print("*"+" ");
	   }
	  
	  System.out.println();
	  }
}

private void pattern23() {
	// TODO Auto-generated method stub
	
//        * 
//      * * 
//    * * * 
//  * * * * 
//* * * * * 
//  * * * * 
//    * * * 
//      * * 
//        * 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 4; col>=row; col--)
	   { System.out.print(" "+" "); }
	  
	  for(int col=1; col<=row; col++)
	   {System.out.print("*" + " "); }
	  
	   System.out.println(); 
	  }
	for(int row = 1; row<=4; row++)
	  { 
	  for(int col = 1; col<=row; col++)
	   { System.out.print(" "+" "); }
	  //System.out.println();
	  
	for(int col=4; col>=row; col--)
	   {System.out.print("*" + " "); }
	  
	   System.out.println(); 
	  }
}

private void pattern22() {
	// TODO Auto-generated method stub
	
	//* * * * * 
	//* * * * 
	//* * * 
	//* * 
	//* 
	//* * 
	//* * * 
	//* * * * 
	//* * * * * 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 5; col>=row; col--)
	   { System.out.print("*"+" ");
	   }
	  
	  System.out.println();
	  }
	for(int row=2;row<=5;row++)
	  {
	  for(int col=1;col<=row;col++)
	  {
	    System.out.print("*" +" ");
	  }
	  System.out.println();
	  }
	  
	  //}
}

private void pattern21() {
	// TODO Auto-generated method stub
	
	//* 
	//* * 
	//* * * 
	//* * * * 
	//* * * * * 
	//* * * * 
	//* * * 
	//* * 
	//* 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 1; col<=row; col++)
	   { System.out.print("*"+" ");
	   }
	  
	  System.out.println();
	  }
	for(int row=1;row<=4;row++)
	  {
	  for(int col=4;col>=row;col--)
	  {
	    System.out.print("*" +" ");
	  }
	  System.out.println();
	  }
	//System.out.println();
}

private void pattern20() {
	// TODO Auto-generated method stub
	
	//1 2 3 4 5 
	//2 1 2 3 4 
	//3 2 1 2 3 
	//4 3 2 1 2 
	//5 4 3 2 1 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = row; col>=1; col--)
	   { System.out.print(col+" "); }
	  
	  for(int col=2; col<=6-row; col++)
	   {System.out.print((col) + " "); }
	  
	   System.out.println(); 
	  }
}

private void pattern19() {
	// TODO Auto-generated method stub
	
	//1 * * * * 
	//1 2 * * * 
	//1 2 3 * * 
	//1 2 3 4 * 
	//1 2 3 4 5 

	
	for(int row = 1; row<=5; row++)
	  {
		for(int col=1; col<=row; col++)
		   {System.out.print((col) + " "); }
	  for(int col = 4; col>=row; col--)
	   { System.out.print("*"+" "); }
	  
	  
	  
	   System.out.println(); 
	  }
}

private void pattern18() {
	// TODO Auto-generated method stub
	
	//* * * * 1 
	//* * * 1 2 
	//* * 1 2 3 
	//* 1 2 3 4 
	//1 2 3 4 5 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 4; col>=row; col--)
	   { System.out.print("*"+" "); }
	  
	  for(int col=1; col<=row; col++)
	   {System.out.print((col) + " "); }
	  
	   System.out.println(); 
	  }
}

private void pattern17() {
	// TODO Auto-generated method stub
	
//          5
//        4  8
//       3  6  9
//      2  4  6  8
//    1  2  3  4  5
	
	for(int row = 5; row>=1; row--)
	  { 
	  for(int col = 1; col<row; col++)
	   { System.out.print(" "+" "); }
	  
	  for(int col=1; col<=6-row; col++)
	   {System.out.print((col*row) + "   "); }
	  
	   System.out.println(); 
	  }
}

private void pattern16() {
	// TODO Auto-generated method stub
	
	//1   2   3   4   5   
	//  2   4   6   8   
	//    3   6   9   
	//      4   8   
	//        5   

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 1; col<row; col++)
	   { System.out.print(" "+" "); }
	  
	  for(int col=1; col<=6-row; col++)
	   {System.out.print((col*row) + "   "); }
	  
	   System.out.println(); 
	  }
}

private void pattern15() {
	// TODO Auto-generated method stub
	
	//1 1 1 1 1 
	//1 2 2 2 2 
	//1 2 3 3 3 
	//1 2 3 4 4 
	//1 2 3 4 5 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 1; col<row; col++)
	   { System.out.print(col+" "); }
	  
	  for(int col=1; col<=6-row; col++)      
	   {System.out.print(row + " "); }
	  
	   System.out.println(); 
	  }
}

private void pattern14() {
	// TODO Auto-generated method stub
	
	//1 2 3 4 5        
	//  1 2 3 4 
	//    1 2 3 
	//      1 2 
	//        1 
	
	
	//1  2  3  4  5  //you get this in 3rd for col+"" --->2space
	//  1  2  3  4  
	//    1  2  3  
	//      1  2  
	//        1 

	
	for(int row = 1; row<=5; row++)
	  { 
	  for(int col = 1; col<row; col++)
	   { System.out.print(" "+" "); }
	  
	  for(int col=1; col<=6-row; col++)
	   {System.out.print(col + " "); }
	  
	   System.out.println(); 
	  }
}

private void pattern13() {
	// TODO Auto-generated method stub
	
	//* 
	//1 * * 
	//1 2 * * * 
	//1 2 3 * * * * 
	//1 2 3 4 * * * * * 
	
	//1
	//12
	//123
	//1234


	
	for(int row = 1; row<=5; row++)
	 {
	 for(int col = 1; col<row; col++)
	  { System.out.print(col); }
	 
	 /*for(int col=1; col<=row; col++)
	   {System.out.print("*" + " "); }*/
	  System.out.println(); 
	 }
}

private void pattern12() {
	// TODO Auto-generated method stub
	
	//* * * * * 
	//1 * * * * 
	//1 2 * * * 
	//1 2 3 * * 
	//1 2 3 4 * 

	
	for(int row = 1; row<=5; row++)
	 {
	 for(int col = 1; col<row; col++)
	  { System.out.print(col+" "); }
	 
	 for(int col=1; col<=6-row; col++)
	   {System.out.print("*" + " "); }
	  System.out.println(); 
	 }
}

private void pattern11() {
	// TODO Auto-generated method stub
	for(int row = 1; row<=5; row++)
	 {
	 for(int col = 1; col<row; col++)
	  { System.out.print(col+" "); }
	 
	 
	  System.out.println(); 
	 }
}

private void pattern10() {
	// TODO Auto-generated method stub
	for(int row=1;row<=5;row++) {
		for(int col=1;col<=row;col++)
		{
			System.out.print("*"+" ");
		}
		System.out.println();
	}
}

private void pattern9() {
	// TODO Auto-generated method stub
	for(int row=5;row>=1;row--) {
		for(int col=1;col<=row;col++)
		{
			System.out.print("*"+" ");
		}
		System.out.println();
	}
}

private void pattern8() {
	// TODO Auto-generated method stub
	// TODO Auto-generated method stub
		for(char row='E';row>='A';row--) {
			for(char col='E';col>=row;col--)
			{
				System.out.print(col+" ");
			}
			System.out.println();
		}
}

private void pattern7() {
	// TODO Auto-generated method stub
	for(char row='A';row<='E';row++) {
		for(char col='E';col>=row;col--)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern6() {
	// TODO Auto-generated method stub
	for(char row='A';row<='E';row++) {
		for(char col='A';col<=row;col++)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern5() {
	// TODO Auto-generated method stub
	for(char row='E';row>='A';row--) {
		for(char col='A';col<=row;col++)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern4() {
	// TODO Auto-generated method stub
	for(int row=5;row>=1;row--) {
		for(int col=5;col>=row;col--)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern3() {
	// TODO Auto-generated method stub
	for(int row=1;row<=5;row++) {
		for(int col=5;col>=row;col--)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern2() {
	// TODO Auto-generated method stub
	for(int row=1;row<=5;row++) {
		for(int col=1;col<=row;col++)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void pattern1() {
	// TODO Auto-generated method stub
	for(int row=5;row>=1;row--) {
		for(int col=1;col<=row;col++)
		{
			System.out.print(col+" ");
		}
		System.out.println();
	}
}

private void alphabet1() {
	// TODO Auto-generated method stub
	for(int row=1;row<=5;row++) {
		for(char col = 'A'; col<='E'; col++)
	    {   System.out.print(row + " "); }
	System.out.println();
		}
}

private void alphabet() {
	// TODO Auto-generated method stub
	for(char row='A';row<='E';row++) {
	for(char col = 'A'; col<='E'; col++)
    {   System.out.print(row + " "); }
System.out.println();
	}
}

private void simple4() {
	// TODO Auto-generated method stub
	for(int row = 5; row>=1; row--)
	{
	for(int col = 1; col<=5; col++)
	    { System.out.print(row + " "); }
	System.out.println(); 
	}
}

private void simple3() {
	// TODO Auto-generated method stub
	for(int row = 1; row<=5; row++)
	{
	for(int col = 1; col<=5; col++)
	    { System.out.print(row + " "); }
	System.out.println(); 
	}
}

private void simple2() {
	// TODO Auto-generated method stub
	for(int row = 1; row<=5; row++)
	{
	for(int col = 5; col>=1; col--)
	    { System.out.print(col + " "); }
	System.out.println(); 
	}
}

private void simple1() {
	// TODO Auto-generated method stub
	for(int row = 1; row<=5; row++)
	{
	for(int col = 1; col<=5; col++)
	    { System.out.print(col + " "); }
	System.out.println(); 
	}
}

private void simple() {
	// TODO Auto-generated method stub
	for(int col = 1; col<=5; col++)
	{ System.out.print(col + " "); }
	for(int col = 1; col<=5; col++)
	{ System.out.print(col + " "); }
	for(int col = 1; col<=5; col++)
	{ System.out.print(col + " "); }

}

}

Leave a comment

Design a site like this with WordPress.com
Get started