Print Star Pattern - 14 | Java Programs

Output:

*** Star Pattern 14 ***

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

Click Here For Java Online Compiler

Solution:

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

    public static void main(String[] args) {
        int rows = 7;
        System.out.println("*** Star Pattern 14 ***" + "\n");
        for (int i = 0; i < rows; i++) {
            if (i == 0 || i == 6) {
                for (int j = 0; j < rows; j++) {
                    System.out.print("*");
                }
                System.out.println();
            }
            if (i >= 1 && i <= 5) {
                for (int j = 0; j < rows; j++) {
                    if (j == 0 || j == 6) {
                        System.out.print("*");
                    } else if (j >= 1 && j <= 5) {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon