Print Star Pattern - 12 | Java Programs

Output:

*** Star Pattern 12 ***

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

Click Here For Java Online Compiler

Solution:

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

    public static void main(String args[]) {
        int space = 0;
        System.out.println("*** Star Pattern 12 ***" + "\n");
        for (int i = 5; i >= 1; i--) {
            //first part of row
            for (int j = i; j >= 1; j--) {
                System.out.print("*");
            }

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

            //second part of row
            for (int j = i; j >= 1; j--) {
                System.out.print("*");
            }

            System.out.println();
            space = space + 2;
        }

        space = 8;
        for (int i = 1; i <= 5; i++) {
            //first part of row
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }

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

            //second part of row
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }

            System.out.println();
            space = space - 2;
        }

    }
}
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