Sunday 16 August 2020

A

  #Program to Print alphabet 'A'  in Star Pattern

Expected Output:

     *    
   *  *   
  * * *  
 *      * 
*        *

Code in Java:

public class AlphabetPrinting {
void A(){
int n=5; //first take n=5
int px=n; //declare px=row
int py=n; //declare py=column
for(int i=1; i<=5; i++) //Outer loop for number of rows
{
for(int j=1; j<10; j++) //Inner loop for number of columns
{
if(j==px||j==py || i==n/2+1 && j==5) //if condition to print the Stars
{
System.out.print("*"); //printing stars
}
else
{
System.out.print(" "); //printing white spaces
}
}
px++; 
py--;
System.out.println(); 
}
System.out.println(); //printing newline after each row
}
public static void main(String a[]){
AlphabetPrinting obj = new AlphabetPrinting(); //Object creation
obj.A(); //function calling 
}
}








No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32