Saturday, 22 August 2020

E

 

#Program to Print alphabet 'E' in Star Pattern

Expected Output:

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

Code in Java:


public class Epattern {
void E(){
int n=5;
for(int i=1; i<=n; i++)//Outer loop for number of rows
{
for(int j=1; j<=n;j++)//inner loop for number of columns
{
//if condition to print the E pattern Stars
if(i==1||i==5||i==n/2+1||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) {
Epattern obj=new Epattern();
obj.E();
}
}



No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32