Pattern 10 - Pyramid generation program in java


Write a program to generate this Pattern.




Must read:   Merge Sort.


Full Program/SourceCode >
package pyramid;
/** Copyright (c), AnkitMittal  JavaMadeSoEasy.com */
public class Pyramid10 {
   public static void main(String[] args) {
          int j;
          int rows = 8;
          for (int i = 1; i <= rows; i++) {
                 for (j = 1; j <= rows - i; j++)   // for initial spacing.
                       System.out.print(" ");
                 for (int k = j + 1; k <= rows; k++) //creates left half.
                       System.out.print("*");
                
                 for (int k = rows; k > j - 1; k--)//creates right half.
                       System.out.print("*");
                
                 System.out.println();
          }
   }
}
/*OUTPUT
   *
     ***
    *****
   *******
  *********
 ***********
*************
***************
*/


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>


>Pattern/Pyramid generating programs





eEdit
Must read for you :