Coders Packet

Diagonal star pattern in Java

By AZAHARUDDIN SAIKH

Diagonal star pattern in java program will generate a rectangular pattern composed of star(*) of entered number by user. This program should be accomplished by using for loop.

EXAMPLE 1:

Prin square star(5); should print the following:

=>>NOTE: For text in Code Blocks below, use code icon {...} on Udemy

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


Explanation:

***** 5 stars
** ** 2 stars space 2 stars
* * * 1 star space 1 star space 1 star
** ** 2 stars space 2 stars
***** 5 stars

 

EXAMPLE 2

printSquareStar(8); should print the following:

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


##The patterns above consist of a number of rows and columns (where number is the number of rows to print). For each row or column, stars are printed based on four conditions (Read them carefully):

* In the first or last row

* In the first or last column

* When the row number equals the column number

* When the column number equals rowCount - currentRow + 1 (where currentRow is current row number)

Download Complete Code

Comments

No comments yet