Saturday, 6 June 2015

Pyramid Design in Java

    1
   232
  34543
 4567654
567898765
public class PyramidDesign
{
  public static void main(String soham[])
  {
    String str = "123456789";
    
    PyramidDesign pd = new PyramidDesign();

    for(int i=0; i<=4; i++)
    {
      pd.display(i,str);
      System.out.println();
    }
  }
  
  public void display(int start,String str)
  {
    int i,j;
    for(i=start; i<=(start+start); i++)
    {
      System.out.print(""+str.charAt(i));
    }
    
    for(j=(i-2); j >= start; j--)
    {
      System.out.print(""+str.charAt(j));
    }
  }
}

1 comment:

  1. hi admin.i am really love it your blog.Because your explanation wise all the topics are too good..
    Java Training in Marathahalli
    Python Training in Marathahalli

    ReplyDelete