Following Code will print a Diamond Pattern of User Specified Number of Rows:
Code::
import java.util.*;
public class Pattern
{
public static void main(String[] nt)
{
Scanner in=new Scanner(System.in);
System.out.print("Enter number of Rows: ");
int n=in.nextInt();
for(int i=1;i<=n;i++)
{
for(int sp=n-i;sp>0;sp--)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
System.out.print("* ");
}
System.out.println();
}
for(int i=n;i>0;i--)
{
for(int sp=0;sp<n-i;sp++)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Code::
import java.util.*;
public class Pattern
{
public static void main(String[] nt)
{
Scanner in=new Scanner(System.in);
System.out.print("Enter number of Rows: ");
int n=in.nextInt();
for(int i=1;i<=n;i++)
{
for(int sp=n-i;sp>0;sp--)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
System.out.print("* ");
}
System.out.println();
}
for(int i=n;i>0;i--)
{
for(int sp=0;sp<n-i;sp++)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Output::