Java Pyramid

  1. /*

  2. Java Pyramid Example

  3. This Java Pyramid example shows how to generate pyramid or triangle like

  4. given below using for loop.

  5.  

  6. *

  7. **

  8. ***

  9. ****

  10. *****

  11. */

  12.  

  13. public class JavaPyramid1 {

  14.  

  15. public static void main(String[] args) {

  16.  

  17. for(int i=1; i<= 5 ;i++){

  18.  

  19. for(int j=0; j < i; j++){

  20. System.out.print("*");

  21. }

  22.  

  23. //generate a new line

  24. System.out.println("");

  25. }

  26. }

  27. }

  28.  

  29. /*

  30. Output of the above program would be

  31. *

  32. **

  33. ***

  34. ****

  35. *****

  36. */

0 comments: