Как бы вы напечатали бриллиант рекурсивно, используя Java, зная только его размер?
Размер 5 дает:
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
Код, который у меня есть
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=statSizeLarge) {
count = 0;
System.out.println();
dia(statSize,size-1,count);
}
} // ends Else
}
Вывод:
Enter commands:
diamond 3
******
** ****
* ****
* ****
** ****
* ****
* ****
Подробнее здесь: https://stackoverflow.com/questions/513 ... lank-lines