#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 } }
No comments:
Post a Comment
If you have any doubts, please let me know