Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

star pyramid program in java

public static void StarPyramid(int n)
{
    for (int i = 0; i < n; i++) 
    {
        var bol = true;
        for (int j = 0; j < 2*n; j++) 
        {
            if(j+i>=n && j<=n+i)
            {
                if(bol)System.out.print("*");
                else System.out.print(" ");
                bol=!bol;
            }
            else System.out.print(" ");
        }
        System.out.println();
    }
}
//for n =7
       *      
      * *     
     * * *    
    * * * *   
   * * * * *  
  * * * * * * 
 * * * * * * *
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #star #pyramid #program #java
ADD COMMENT
Topic
Name
5+4 =