package test;
public class diamond {
int total = 0;
int width = 1;
int count = 0;
boolean flag = false;
public void dia(int n){
if(flag == false && n == total+1){
width = (n-total)*2-1;
count = (total*2)-width-2;
flag = true;
}
if(n == total*2){
return;
}
if(n <= total){
if(width != total){
System.out.print(" ");
width++;
dia(n);
}else{
if(count!=(n*2)-1){
System.out.print("*");
count++;
dia(n);
}else{
System.out.println();
n++;
width = n;
count = 0;
dia(n);
}
}
}else{
if(width > 0){
System.out.print(" ");
width--;
dia(n);
}else{
if(count>0){
System.out.print("*");
count--;
dia(n);
}else{
System.out.println();
n++;
width = n-total;
count = (total*2)-(width*2)-1;
dia(n);
}
}
}
}
public static void main(String[] args) {
diamond d = new diamond();
d.total = 5;
d.dia(1);
}
}