class triangle1{
int total = 0;
int width = 0;
triangle1(int x){
this.total = x;
}
public void triangle1(int n){
if(n == total+1){
return;
}
if(width != n){
System.out.print("*");
width++;
triangle1(n);
}else{
System.out.println();
n++;
width = 0;
triangle1(n);
}
}
}
class triangle2{
int total = 0;
int width = 0;
triangle2(int x){
this.total = x;
}
public void triangle2(int n){
if(n == total+1){
return;
}
if(width != total){
System.out.print("*");
width++;
triangle2(n);
}else{
System.out.println();
width = n;
n++;
triangle2(n);
}
}
}
class triangle3 {
int total = 0;
int width = 1;
int count = 0;
triangle3(int x){
this.total = x;
}
public void triangle3(int n){
if(n == total+1){
return;
}
if(width != total){
System.out.print(" ");
width++;
triangle3(n);
}else{
if(count!=n){
System.out.print("*");
count++;
triangle3(n);
}else{
System.out.println();
n++;
width = n;
count = 0;
triangle3(n);
}
}
}
}
class triangle4 {
int total = 0;
int width = 0;
int count = 0;
triangle4(int x){
this.total = x;
this.width = x;
}
public void triangle4(int n){
if(n == total+1){
return;
}
if(width != total){
System.out.print(" ");
width++;
triangle4(n);
}else{
if(count!=total){
System.out.print("*");
count++;
triangle4(n);
}else{
System.out.println();
width = total-n;
count = n;
n++;
triangle4(n);
}
}
}
}
public class triangle {
public static void main(String[] args) {
int i = 5;
System.out.println("-------------start triangle1-------------");
triangle1 t1 = new triangle1(i); //원하는 출력 수.
t1.triangle1(1); //디폴트 1.
System.out.println("-------------end triangle1-------------");
System.out.println("-------------start triangle2-------------");
triangle2 t2 = new triangle2(i); //원하는 출력 수.
t2.triangle2(1); //디폴트 1.
System.out.println("-------------end triangle2-------------");
System.out.println("-------------start triangle3-------------");
triangle3 t3 = new triangle3(i); //원하는 출력 수.
t3.triangle3(1); //디폴트 1.
System.out.println("-------------end triangle3-------------");
System.out.println("-------------start triangle4-------------");
triangle4 t4 = new triangle4(i); //원하는 출력 수.
t4.triangle4(1); //디폴트 1.
System.out.println("-------------end triangle4-------------");
}
}