#Program to Print alphabet 'B' in Star Pattern
Expected Output:
* * * *
* *
* *
* * * *
* *
* *
* * * *
Code in Java:
public class BAlphabetPrinting {
void B()
{
for(int i=1; i<=7; 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 B pattern Stars
if(j==1||((i==1||i==4||i==7)&&(j<5&&j>1))||(j==5&&(i!=1&&i!=4&&i!=7)))
{
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)
{
BAlphabetPrinting obj = new BAlphabetPrinting();
obj.B();
}
}
No comments:
Post a Comment
If you have any doubts, please let me know