Diamond Pattern
import java.util.*;
// import java.util.Scanner;
public class practice {
public static void diamondpattern(int n){
for(int row=1;row<=n;row++){
for(int space=n-row;space>=1;space--){
System.out.print(" ");
}
for(int col=1;col<=2*row-1;col++){
System.out.print("*");
}
System.out.print("\n");
}
for(int row=n;row>=1;row--){
for(int space=n-row;space>=1;space--){
System.out.print(" ");
}
for(int col=1;col<=2*row-1;col++){
System.out.print("*");
}
System.out.print("\n");
}
}
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
int n;
System.out.println("Enter the size to print diamond pattern");
n=s.nextInt();
diamondpattern(n);
}
}
Comments
Post a Comment