ADVERTISEMENT
ADVERTISEMENT

Java program to print Pattern of Stars

This section contains programs on Pattern of Stars, these programs will print different pattern of star series.

Pattern of Series Programs in Java

Program 1# Java program to print following pattern of series:

        *
       * *
      * * *
     * * * *
    * * * * *
public class PrintPattern {
  public static void main(String args[]) {
    int space = 4;
    for (int i = 1; i <= 5; i++) {
      //print spaces
      for (int j = 1; j <= space; j++)
        System.out.print(" ");

      //print stars
      for (int j = 1; j <= i; j++)
        System.out.print("* ");

      //print new line
      System.out.println();
      space--;

    }
  }
}
ADVERTISEMENT

Program 2# Java program to print following pattern of series:

    * * * * *
     * * * *
      * * *
       * *
        *    
public class PrintPattern {
  public static void main(String args[]) {
    int space = 0;
    for (int i = 5; i >= 1; i--) {
      //print spaces
      for (int j = 1; j <= space; j++)
        System.out.print(" ");

      //print stars
      for (int j = 1; j <= i; j++)
        System.out.print("* ");

      //print new line
      System.out.println();
      space++;

    }
  }
}
ADVERTISEMENT

Program 3# Java program to print following pattern of series:

    *        *
    **      **
    ***    ***
    ****  ****
    **********   
public class PrintPattern {
  public static void main(String args[]) {
    int space = 8;
    for (int i = 1; i <= 5; i++) {
      //print first part of the row
      for (int j = 1; j <= i; j++)
        System.out.print("*");

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

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

      //print new lint
      System.out.println();
      space = space - 2;
    }
  }
}
ADVERTISEMENT

Program 4# Java program to print following pattern of series:

    **********
    ****  ****
    ***    ***
    **      **
    *        *
public class PrintPattern {
  public static void main(String args[]) {
    int space = 0;
    for (int i = 5; i >= 1; i--) {
      //print first part of the row
      for (int j = i; j >= 1; j--)
        System.out.print("*");

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

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

      //print new lint
      System.out.println();
      space = space + 2;

    }
  }
}
ADVERTISEMENT

Program 5# Java program to print following pattern of series:

    **********
    ****  ****
    ***    ***
    **      **
    *        *
    *        *
    **      **
    ***    ***
    ****  ****
    **********
public class PrintPattern {
  public static void main(String args[]) {
    int space = 0;
    for (int i = 5; i >= 1; i--) {
      //print first part of the row
      for (int j = i; j >= 1; j--)
        System.out.print("*");

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

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

      //print new lint
      System.out.println();
      space = space + 2;
    }

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

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

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

      //print new lint
      System.out.println();
      space = space - 2;
    }

  }
}
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.