public class Main
{
public static void main
(String[] args
) { System.
out.
println("Dynamic Pattern for n = 5"); printPattern(5);
}
// print dynamic pattern edge cases handle
static void printPattern(int n){
if(n < 3){
System.
out.
println("The Number should be greater than equals to 3"); } else if (n%2 == 0){
System.
out.
println("The Number must be odd digit"); } else {
patternHelper(n);
}
}
// print pattern helper
static void patternHelper(int n){
for(int i = 0; i < n+2; i++){
if(i != n+1){
for(int j = 0; j < n-1 ; j++){
}
} else {
for(int j = 0; j < n-1 ; j++){
}
}
if(i == 0){
for(int j = 0; j < n+2 ; j++){
}
} else if(i == (n+2)/2){
for(int j = 0; j < n ; j++){
}
}
}
}
}
cHVibGljIGNsYXNzIE1haW4KewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoJCVN5c3RlbS5vdXQucHJpbnRsbigiRHluYW1pYyBQYXR0ZXJuIGZvciBuID0gNSIpOwoJCXByaW50UGF0dGVybig1KTsKCX0KCQoJCi8vIAlwcmludCBkeW5hbWljIHBhdHRlcm4gZWRnZSBjYXNlcyBoYW5kbGUKCXN0YXRpYyB2b2lkIHByaW50UGF0dGVybihpbnQgbil7CiAgICBpZihuIDwgMyl7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJUaGUgTnVtYmVyIHNob3VsZCBiZSBncmVhdGVyIHRoYW4gZXF1YWxzIHRvIDMiKTsKICAgIH0gZWxzZSBpZiAobiUyID09IDApewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiVGhlIE51bWJlciBtdXN0IGJlIG9kZCBkaWdpdCIpOwogICAgfSBlbHNlIHsKICAgICAgICBwYXR0ZXJuSGVscGVyKG4pOwogICAgfQp9CgovLyBwcmludCBwYXR0ZXJuIGhlbHBlcgpzdGF0aWMgdm9pZCBwYXR0ZXJuSGVscGVyKGludCBuKXsKICAgIAogICAgCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbisyOyBpKyspewogICAgICAgIAogICAgICAgIGlmKGkgIT0gbisxKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG4tMSA7IGorKyl7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCIgICIpOwogICAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG4tMSA7IGorKyl7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCIqICIpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIFN5c3RlbS5vdXQucHJpbnQoImUgIik7CiAgICAgICAgCiAgICAgICAgaWYoaSA9PSAwKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG4rMiA7IGorKyl7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KCIqICIpOwogICAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmKGkgPT0gKG4rMikvMil7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuIDsgaisrKXsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIiogIik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgCiAgICB9Cn0KCn0K