Pages

Sunday 20 November 2016

Problem 30 - Pyramid

  1. public class JavaPyramid3 {
  2.         public static void main(String[] args) {
  3.                
  4.                 for(int i=1; i<= 5 ;i++){
  5.                        
  6.                         for(int j=0; j < i; j++){
  7.                                 System.out.print("*");
  8.                         }
  9.                        
  10.                         //generate a new line
  11.                         System.out.println("");
  12.                 }
  13.                
  14.                 //create second half of pyramid
  15.                 for(int i=5; i>0 ;i--){
  16.                        
  17.                         for(int j=0; j < i; j++){
  18.                                 System.out.print("*");
  19.                         }
  20.                        
  21.                         //generate a new line
  22.                         System.out.println("");
  23.                 }
  24.         }
  25. }



0 comments:

Post a Comment