Subscribe to Unconventional Codes        RSS Feed
-----

Java Program to Print Pyramid of Stars

Icon 1 Comments
Recently i wrote Java code to Print Pyramid of Stars
Here is the code,I hope it will be useful for java Beginners
public class stars {
    public static void main(String[] args) {
         int n = 5;
         int space = n-1;
         int a;                  
         for(int i = 0; i < n; i++)
         {    
            a = 2*i+1;
            for(int j = 1; j <= space+a; j++)
            {
                if(j <= space)
                    System.out.print(' ');
                else
                    System.out.print('*');
            }
            System.out.println();
            space--;
        }    
    }
}


Output :


*
***
*****
*******
*********

1 Comments On This Entry

Page 1 of 1

vividvilla Icon

14 April 2012 - 07:28 AM
Sorry the output is not formatted correctly in the above code,
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

July 2014

S M T W T F S
  12345
6789101112
13141516171819
20212223 24 2526
2728293031  

Tags

    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories