Choose Your Language

Thursday 4 April 2013

Program to print Diamond shape

public class Diamond {

    public static void main(String[] args) {
        for (int i = 1; i < 10; i += 2) {
          for (int j = 0; j < 10 - i / 2; j++)
            System.out.print(" ");

          for (int j = 0; j < i; j++)
            System.out.print("*");

          System.out.print("\n");
        }

        for (int i = 7; i > 0; i -= 2) {
          for (int j = 0; j < 10 - i / 2; j++)
            System.out.print(" ");

          for (int j = 0; j < i; j++)
            System.out.print("*");

          System.out.print("\n");
        }
   
      }
    }

output:

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

2 comments:

  1. really great, thanks a lot...

    ReplyDelete
  2. Thank you so much, please make some more that'll help a lot.

    ReplyDelete