Showing posts with label Home. Show all posts
Showing posts with label Home. Show all posts

Monday, 24 August 2020

Z

 

#Program to Print alphabet 'Z' in Star Pattern

Expected Output:

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


Code in Java:
public class Z 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
			//if condition to print the Z pattern Stars
			if(i==1||i==5||i==2&&j==4||i==4&&j==2||i==3&&j==3)
			{
				System.out.print("* ");//printing stars
			}
			else
			{
				System.out.print("  ");//printing white spaces
			}
			}
		System.out.println();
		}
	System.out.println();//printing newline after each row
	}
}      
      

Y

 

#Program to Print alphabet 'Y' in Star Pattern

Expected Output:

*       *
  *   * 
    *  
    *  
    *  


Code in Java:
public class Y 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
			//if condition to print the Y pattern Stars
				if(i==1&&j==5||i==2&&j==4||j==i&& i<=3||j==3&&i>3)
				{
					System.out.print("*");//printing stars
				}
				else
				{
				System.out.print(" ");//printing white spaces
				}
			}
			System.out.println();
		}
		System.out.println();//printing newline after each row
	}
}      
      

X

 

#Program to Print alphabet 'X' in Star Pattern

Expected Output:

*        *
  *    * 
     *  
  *    * 
*        *


Code in Java:
public class X 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
			//if condition to print the X pattern Stars
			if(i==j||i==1&&j==5||i==2&&j==4||i==4&&j==2||i==5&&j==1)
			{
				System.out.print("*");//printing stars
			}
			else
			{
				System.out.print(" ");//printing white spaces
			}
			}
		System.out.println();
		}
		System.out.println();//printing newline after each row
	}
}      
      

W

 

#Program to Print alphabet 'W' in Star Pattern

Expected Output:


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


Code in Java:
public class W 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=7; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=7;j++)//inner loop for number of columns
			{
				//if condition to print the W pattern Stars 
				if(j==1||j==7||i==j&&i>=4||i==6&&j==2||i==5&&j==3)
				{
					System.out.print("* ");//printing stars
				}
				else 
				{
					System.out.print("  ");//for white spaces
				}
			}
			System.out.println();
		}
		System.out.println();//printing newline after each row
	}
}       
  

V

 

#Program to Print alphabet 'V' in Star Pattern

Expected Output:

*       *
 *     * 
  *   *  
   * *   
    *    


Code in Java:
public class V 
{
	public static void main(String[] args) 
	{
    	//px and py used to increment and decrement rows and columns
		int n=5, px=1, py=n*2-1;
		for(int i=1; i<=n; i++)//Outer loop for number of rows
		{
			for(int j=1; j<n*2; j++)//inner loop for number of columns
			{
			//if condition to print the V pattern Stars
			if(j==px||j==py) 
			{
				System.out.print("*");//printing stars
			}
			else
			{
				System.out.print(" ");//printing white spaces
			}
			}
		px++;
		py--;
		System.out.println();//printing newline after each row		
		}
	}
}      
      


U

 

#Program to Print alphabet 'U' in Star Pattern

Expected Output:

*         *
*         *
*         *
*         *
  * * * 

Code in Java:
public class Upattern {
	 void U()
	 {
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
			//if condition to print the U pattern Stars
			if(i==5&&j>1&&j<5||j==1&&i<5||j==5&&i<5)
			{
				System.out.print("*");//printing stars
			}
			else
			{
				System.out.print(" ");//printing white spaces
			}
			}
            System.out.println();
		}
        System.out.println();//printing newline after each row
	 }
	public static void main(String[] args) 
    {
		Upattern obj=new Upattern();
		obj.U();
	}
}        
  

T

#Program to Print alphabet 'T' in Star Pattern

Expected Output:

* * * * *

     *  

     *  

     *  

Code in Java: 
public class Tpattern 
{
	void T()
	 {
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
				//if condition to print the T pattern Stars
					if(i==1 || j==3)
					{
					System.out.print("*");//printing stars
					}
					else
					{
					System.out.print(" ");//for white spaces
					}
				}System.out.println();
			}System.out.println();//printing newline after each row
	 }
	public static void main(String[] args) 
    {
		Tpattern obj=new Tpattern();
		obj.T();
	}
}    


S

 

#Program to Print alphabet 'S' in Star Pattern

Expected Output:

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


Code in Java:

public class S 
{
	public static void main(String[] args) 
	{
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
			//if condition to print the S pattern Stars
			if(i==1&&j>1||i==5&&j<5||i==3||i==2&&j==1||i==4&&j==5)
			{
				System.out.print("*");//printing stars
			}
			else
			{
				System.out.print(" ");//printing white spaces
			}
			}
			System.out.println();
		}
		System.out.println();//printing newline after each row
	}
}
 
  


P

 

#Program to Print alphabet 'P' in Star Pattern

Expected Output:

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


Code in Java:


public class Ppattern {
void P()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the P pattern Stars
if(i==1&&j<5||j==1||i==3&&j<5||i==2&&j==5)
{
System.out.print("*");//printing stars
}
else
{
System.out.print(" ");//printing white spaces
}
}System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Ppattern obj=new Ppattern();
obj.P();
}
}








Q

 

#Program to Print alphabet 'Q' in Star Pattern

Expected Output:

  * *  
*     * 
*     * 
  *** 
        *


Code in Java:


public class Qpattern {
void Q()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the Q pattern Stars
if((i==1&&j>1&&j<4)||i==4&&j>1&&j<5||j==1&&i>1&&i<4||j==4&&i>1&&i<5||i==5&&j==5)
{
System.out.print("*");//printing stars
}
else
{
System.out.print(" ");//printing white spaces
}
}System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Qpattern obj=new Qpattern();
obj.Q();
}
}



R

 

#Program to Print alphabet 'R' in Star Pattern

Expected Output:

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


Code in Java:


public class Rpattern {
void R()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the R pattern Stars
if(i==1&&j<5||j==1||i==3&&j<5||i==2&&j==5||i==j&&i>3)
{
System.out.print("*");//printing stars
}
else
{
System.out.print(" ");//printing white spaces
}
}System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Rpattern obj=new Rpattern();
obj.R();
}
}

O

 

#Program to Print alphabet 'O' in Star Pattern

Expected Output:

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


Code in Java:


public class Opattern {
void O()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the S pattern Stars
if((i==1&&j>1&&j<5)||i==5&&j>1&&j<5||j==1&&i>1&&i<5||j==5&&i>1&&i<5)
{
System.out.print("*");//printing stars
}
else
{
System.out.print(" ");//printing white spaces
}
}System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Opattern obj=new Opattern();
obj.O();
}
}


N

 

#Program to Print alphabet 'N' in Star Pattern

Expected Output:

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

Code in Java:


public class Npattern {
void N()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the N pattern Stars
if(i==j||j==1||j==5)
{
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}
System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Npattern obj=new Npattern();
obj.N();
}

}



M

 

#Program to Print alphabet 'M' in Star Pattern

Expected Output:

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

Code in Java:


public class Mpattern {
void M()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=7;j++)//inner loop for number of columns
{
//if condition to print the M pattern Stars
if(j==1||j==7||i==j&&i<=4||i==2&&j==6||i==3&&j==5)
{
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Mpattern obj=new Mpattern();
obj.M();
}
}



L

 

#Program to Print alphabet 'L' in Star Pattern

Expected Output:

*    
*    
*    
*    
* * * * *


Code in Java:


public class Lpattern {
void L()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the L pattern Stars
if(i==5||j==1)
{
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Lpattern obj=new Lpattern();
obj.L();
}
}



K

 

#Program to Print alphabet 'K' in Star Pattern

Expected Output:

*     *
*   * 
* *  
*   * 
*     *

Code in Java:


public class Kpattern {
void K()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the K pattern Stars
if(j==1||i==j&&i>=3||i==1&&j==5||i==2&&j==4)
{
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Kpattern obj=new Kpattern();
obj.K();
}
}




J

#Program to Print alphabet 'J' in Star Pattern

Expected Output:

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

Code in Java:

public class Jpattern {
void J()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the J pattern Stars
if(i==1||j==5||i==5&&j>=2|| i==4&&j==1)
{
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Jpattern obj=new Jpattern();
obj.J();
}
}





I

 

#Program to Print alphabet 'I' in Star Pattern

Expected Output:

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

Code in Java:

public class Ipattern {
void I()
{
for(int i=1; i<=7; i++)//Outer loop for number of rows
{
for(int j=1; j<=7;j++)//inner loop for number of columns
{
//if condition to print the I pattern Stars
if(i==1||i==7||j==4)
{
System.out.print("*");//printing stars
}
else
{
System.out.print(" ");//printing white spaces
}
}System.out.println();
}System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Ipattern obj=new Ipattern();
obj.I();
}
}








Saturday, 22 August 2020

H

 

#Program to Print alphabet 'H' in Star Pattern

Expected Output:

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

Code in Java:


public class Hpattern {
void H()
{
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the H pattern Stars
if(j==1||i==3||j==5)
{
System.out.print("*");
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}
System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Hpattern obj = new Hpattern();
obj.H();
}
}



G

 

#Program to Print alphabet 'G' in Star Pattern

Expected Output:

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

Code in Java:


public class Gpattern {
void G() {
for(int i=1; i<=5; i++)//Outer loop for number of rows
{
for(int j=1; j<=5;j++)//inner loop for number of columns
{
//if condition to print the G pattern Stars
if((i==1&&(j>1)||i==5&&(j>1))||(j==1 && (i!=1&&i!=5))||(j==5&&i>2)||(i==3&&j>2))
{ 
System.out.print("*");//printing stars
}
else 
{
System.out.print(" ");//printing white spaces
}
}
System.out.println();
}
System.out.println();//printing newline after each row
}
public static void main(String[] args) {
Gpattern obj=new Gpattern();
obj.G();
}
}



Pattern 31 & 32