Java Diamond Pattern

In one of my previous post we have printed the Pyramid pattern. In this short tutorial we are going to print the Diamond pattern using java for loop.


public class StarDiamond {

    public static void main(String[] args) {

        int num = 5;
        for (int i = 1; i <= num; i++) {
            for (int j = num; j >= i; j--) {
                System.out.print(" ");
            }
            for (int m = 1; m <= i; m++) {
                System.out.print(" *");
            }
            System.out.print("\n");
        }
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }
            for (int m = num; m >= i; m--) {
                System.out.print(" *");
            }
            System.out.print("\n");
        }
    }
}


Output:




You may also like:

Pyramid Pattern







12 comments:

  1. this code was really help to me thanks

    ReplyDelete
  2. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    ReplyDelete
  3. I have read your blog its very attractive and impressive. I like it your blog.


    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  4. How to Write these pattern code
    *
    ** **
    *** ***
    ** **
    *


    How to Write this program to Print Star Pattern in Java

    ReplyDelete
  5. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
    or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete
  6. Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.

    ReplyDelete
  7. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Best Training Instittue

    ReplyDelete
  8. I have read your blog its very attractive and impressive. I like it your blog.
    Best Training and Real Time Support
    Android Training

    ReplyDelete