DIAMOND PATTERN CREATION.
We have created simple java program to print diamond pattern as shown in output. We have create * pattern in diamond form.
JAVA CODE :-
import java.util.Scanner;
public class pattern2
{
public static void main(String[] args)
{
int n,i,j;
Scanner s=new Scanner(System.in);
System.out.print("Enter number of rows: ");
n=s.nextInt();
s.close();
for(i=0;i<n;i++)
{
for(j=0;j<(n-i)-1;j++)
{
System.out.print(" ");
}
for(j=0;j<i+1;j++)
{
System.out.print("* ");
}
System.out.print("\n");
}
for(i=n-1;i>0;i--)
{
for(j=n-i;j>0;j--)
{
System.out.print(" ");
}
for(j=i;j>0;j--)
{
System.out.print("* ");
}
System.out.print("\n");
}
}
}
0 Comments