Pattern 6 - Pyramid generation program in java


Write a program to generate this Pattern.



                     HashMap Custom implementation.  


Full Program/SourceCode >
package pyramid;
import java.util.Scanner;
/** Copyright (c), AnkitMittal  JavaMadeSoEasy.com */
public class Pyramid6 {
   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 = n; i >0; i--) {
                 for (int j = i,k=1; k <= i; j--,k++) {
                       System.out.print(j);
                 }
                 System.out.println("");
          }
   }
}
/*OUTPUT
Enter n : 5
54321
4321
321
21
1
*/


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>


No comments:

Post a Comment