Java: Imprime un diamante de forma recursiva
¿Cómo imprimirías un diamante de forma recursiva utilizando Java con solo el tamaño dado?
Un tamaño de 5 produce:
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
Code tengo hasta ahora
public static void dia(int statSize, int size,int count) {
int statSizeLarge = (statSize*2)+1;
// Params:
// statSize == static size, never change this
// size == variable size, change this
// count == counter
if(size==0) {
System.out.println();
} else {
// is the counter smaller then the size
// if yes, increment and keep printing
if(count<size){
System.out.print("*");
}
// is greater then size?
// if yes, move on, print
// a few more stars
if((count<=statSizeLarge)){
if(count<statSize+1 && (count>size)){
System.out.print(" ");
}else if (count>size+1){
System.out.print("*");
} else {}
dia(statSize,size,count+1);
}
// reset count, move to next element
if(count>=statSizeLarge) {
count = 0;
System.out.println();
dia(statSize,size-1,count);
}
} // ends Else
}
Salida
Enter commands:
diamond 3
******
** ****
* ****
* ****
** ****
* ****
* ****