Write a program to print the following pattern:-
Input:-
9 (always odd number)
Output:-
bbbb*bbbb
bbb***bbb
bb*****bb
b*******b
*********
b*******b
bb*****bb
bbb***bbb
bbbb*bbbb
Code:-
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int len=n/2;
String str="";
for(int i=0;i<len;i++){
str+="b";
}
int temp=len-1;
String str1=str;
int temp1=0;
int len1=n/2;
for(int i=0;i<n;i++){
if(i<len){
System.out.println(str+"*"+str1);
str=str.substring(0,temp)+'*'+str.substring(temp+1);
temp--;
str1=str1.substring(0,i)+'*'+str1.substring(i+1);
}
if(i==len)
{
System.out.println(str+"*"+str1);
str=str.substring(0,temp1)+'b'+str.substring(temp1+1);
temp1++;
str1=str1.substring(0,len1-1)+'b'+str1.substring(len1);
len1--;
}
if(i-1>len){
System.out.println(str+"*"+str1);
str=str.substring(0,temp1)+'b'+str.substring(temp1+1);
temp1++;
str1=str1.substring(0,len1-1)+'b'+str1.substring(len1);
len1--;
}
if(i==n-1)
System.out.println(str+"*"+str1);
}
}
}