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

Recommended Answers

All 4 Replies

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)));
  }

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

That's the output (with stars) that my code produces I doubt that you will get it much simpler than that.

thnx JamesCherrill

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.