Pattern 9 - Pyramid generation program in java


Write a program to generate this Pattern.




                           Factorial using recursion.


Full Program/SourceCode >
package pyramid;
import java.util.Scanner;
/** Copyright (c), AnkitMittal  JavaMadeSoEasy.com */
public class Pyramid9Double {
   public static void main(String[] args) {
         
          Scanner scanner = new Scanner(System.in);
          System.out.print("Enter n : ");  
          int n = scanner.nextInt();
          System.out.println("");
          for (int i = 1; i <= n; i++) { //it will create upper half
                 for (int j = 1; j <= i; j++) {
                       System.out.print(" *");
                 }
                 System.out.println("");
          }
          for (int i = n; i > 0; i--) { //it will create lower half
                 for (int j = 1; j <=i; j++) {
                       System.out.print(" *");
                 }
                 System.out.println("");
          }
   }
}
/*OUTPUT
Enter n : 4
*
**
***
****
****
***
**
*
*/


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 :