Sunday 16 December 2012

STAR PATTERN PROGRAM FOR DIAMOND SHAPE IN JAVA


Star pattern in Java in diamond shape 


import java.util.Scanner;

/**
 *
 * @author pankaj
 */
public class StarPattern 
{
    public static void main(String[] args)
    {
        System.out.print("Enter no of row u want in star pattern : ");
        Scanner in = new Scanner(System.in);
                int num=in.nextInt();
                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:



Enter no of row u want in star pattern : 5
      *
     * *
    * * *
   * * * *
  * * * * *
  * * * * *
   * * * *
    * * *
     * *
      *




5 comments:

  1. how to print hollow diamond for number of rows

    ReplyDelete
  2. How to make diamond like this:
    https://i.stack.imgur.com/6TcAs.png
    ?

    ReplyDelete
  3. Thanks for sharing this nice and useful information.
    Java star pattern programs .

    ReplyDelete
  4. Thanks for your code, Any One give me this code in Java

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


    How to Write this program to Print Star Pattern in Java

    ReplyDelete
  5. This article regarding Print Star Pattern in Java is common for every java learner and thanks for sharing above codes in java programming.

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

    Please give code for above pattern

    ReplyDelete