class test
{
    public static void main(String []vinnitro)
    {
        int n=5;
        for(int i=1;i<=n;i++)
        {
            if(i<=n/2+1)
            {
            for(int j=1;j<=i;j++)
            {
                System.out.print("*");
            }
            }
            else
            {
            for(int k=n/2+2;k>=i-1;k--)
            {
                System.out.print("*");
            }
            }
            System.out.println();
        }
    }
}

It works as i expected but it is still very difficult to understand for me even if I coded it.
Thnx 4 help in advance

You could make this easier for us by explaining what it's supposed to achieve, or at least posting some sample output, but at a guess, how about

  String stars = "***********************************************";
  int n = 5;
  for (int i = 1; i <= n; i++) {
     System.out.println(stars.substring(0, Math.min(i, n - i + 1)));
  }

Edited 3 Years Ago by JamesCherrill

I want this output:

A
AA
AAA
AA
A
I am achieving this o/p with code too

cant show with stars
but the code is little difficult to remember for me even if I created it.
I want to do it little more easier way rather than this difficult program which is complex because of n/2 etc. in the code

This question has already been answered. Start a new discussion instead.