Butterfly Pattern for even numbers
import java.util.*;
// import java.util.Scanner;
public class practice {
public static void butterflypattern(int n){
int space;
for(int row=1;row<=n/2;row++){
for(int col=1;col<=row;col++){
System.out.print("*");
}
space=n-row*2;
for(int col=1;col<=space;col++){
System.out.print(" ");
}
for(int col=1;col<=row;col++){
System.out.print("*");
}
System.out.print("\n");
}
for(int row=1;row<=n/2;row++){
for(int col=row;col<=n/2;col++){
System.out.print("*");
}
space=2*(row)-2;
for(int col=1;col<=space;col++){
System.out.print(" ");
}
for(int col=row;col<=n/2;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 of square matrix in even number1");
n=s.nextInt();
butterflypattern(n);
}
}
Comments
Post a Comment