언어/Java

Java- 계단 * 출력

ghghdlt 2024. 5. 2. 16:21

int r=0, c=0, start=3, end=3;

//행처리

while(r<4) {

if(start<=c&&end>=c) {

System.out.print("*");

c++;

}

else if(start>c) {

System.out.print(" ");

c++;

}

else if (end+1==c) {

System.out.println(" ");

r++;

c=0;

end++;

start--;

}

}

}

}