Print Star Pattern 16 In Other Way | Java Programs

Star Pattern 16 in another way.

Output:

*** Star Pattern 16 ***

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


Solution:

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

    public static void main(String[] args) {
        System.out.println("*** Star Pattern 16 ***" + "\n");
        int number = 8;

        for (int i = 1; i <= number / 2; i++) {
            for (int j = (number / 2) - 1; j >= i; j--) {
                System.out.print(" ");
            }
            for (int k = 1; k <= i; k++) {
                System.out.print("* ");
            }
            System.out.println();
        }
        for (int i = 2; i <= number / 2; i++) {
            for (int j = 1; j <= i - 1; j++) {
                System.out.print(" ");
            }
            for (int k = number / 2; k >= i; k--) {
                System.out.print("* ");
            }
            System.out.println();
        }

    }
}
Share This :

Related Post



sentiment_satisfied Emoticon