Print Star Pattern 16 | Java Programs

Output:

*** Star Pattern 16 ***

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

Click Here For Java Online Compiler

Solution:

/**
 *
 * @author Alee Ahmed Kolachi
 */
public class StarPattern16 {

    public static void main(String[] args) {

        int noOfRows = 6;
        int midRow = (noOfRows) / 2;
        int row = 1;

        System.out.println("*** Star Pattern 16 ***" + "\n");

        for (int i = midRow; i > 0; i--) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }

            for (int j = 1; j <= row; j++) {
                System.out.print("* ");
            }

            System.out.println();

            row++;
        }
        //Printing lower half of the diamond
        for (int i = 0; i <= midRow; i++) {

            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }
            for (int j = row; j > 0; j--) {
                System.out.print("* ");
            }

            System.out.println();
            row--;
        }
    }
}
Share This :

Related Post

avatar

nice article.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:08



sentiment_satisfied Emoticon