class pyramid1 {
int total = 0;
int width = 1;
int count = 0;
pyramid1(int i){
this.total = i;
}
public void pyramid1(int n){
if(n == total+1){
return;
}
if(width != total){
System.out.print(" ");
width++;
pyramid1(n);
}else{
if(count!=(n*2)-1){
System.out.print("*");
count++;
pyramid1(n);
}else{
System.out.println();
n++;
width = n;
count = 0;
pyramid1(n);
}
}
}
}
class pyramid2 {
int total = 0;
int width = 0;
int count = 1;
pyramid2(int i){
this.total = i;
this.width = i;
}
public void pyramid2(int n){
if(n == total+1){
return;
}
if(width != total){
System.out.print(" ");
width++;
pyramid2(n);
}else{
if(count!=total*2){
System.out.print("*");
count++;
pyramid2(n);
}else{
System.out.println();
width = total-n;
count = n*2+1;
n++;
pyramid2(n);
}
}
}
}
public class pyramid {
public static void main(String[] args) {
int i = 10;
System.out.println("--------------start pyramid1------------------");
pyramid1 p1 = new pyramid1(i);
p1.pyramid1(1);//디폴트 1값.
System.out.println("--------------end pyramid1------------------");
System.out.println("--------------start pyramid2------------------");
pyramid2 p2 = new pyramid2(i);
p2.pyramid2(1);//디폴트 1값.\
System.out.println("--------------end pyramid2------------------");
}
}