Java program to display diamond pattern

Diamond pattern:

java,java program to print diamond star pattern,java program to print diamond pattern of stars,pattern,java programs,java patterns,diamond pattern,star pattern program in java,java program to print numbers in diamond shape,how to print diamond pattern in java,pyramid pattern in java,diamond,diamond pattern program in java,java interview questions,java tutorial,diamond star pattern prohram in java
Diamond pattern

Program Example:

import java.util.Scanner;
public class Diamond
{
public static void main(String[] args)
{
int i,j,k,p,q,r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the values: ");
int n = sc.nextInt();
int spaces = n-1;
for(i=0;i<n;i++)
{
for(j=0;j<spaces;j++)
{
System.out.print(" ");
}
for(k=0;k<=i;k++)
{
System.out.print("* ");
}
spaces--;
System.out.println();
}
spaces = 1;
for(p=(n-1);p>0;p--)
{
for(q=0;q<spaces;q++)
{
System.out.print(" ");
}
for(r=0;r<p;r++)
{
System.out.print("* ");
}
System.out.println();
spaces++;
}

}
}

Output:

Enter the values: 7
      *
     * *
    * * *
   * * * *
  * * * * *
 * * * * * *
* * * * * * *
 * * * * * *
  * * * * *
   * * * *
    * * *
     * *
      *


"If you have any other logic to attain the same result please email the code to sharkrish50@gmail.com"

Comments

Popular posts from this blog

Multiple image upload to database and display from it

PHP Login and Registration script

String methods in java