풀이
package ex03;
public class Test4Me {
public static void main(String[] args) {
int k = 6;
for (int j = 0; j < 5; j++) {
k--;
for (int i = 0; i < k; i++) {
System.out.print("*");
}
System.out.println();
}
}
}
정답
for문 몇 회전 할건지도 변수로 선언
package ex03;
public class Test4T {
public static void main(String[] args) {
// *****
// ****
// ***
// **
// *
String star = "*";
int c = 5;
int row = 5;
for (int k = 0; k < row; k++) {
for (int i = 0; i < c; i++) {
System.out.print(star);
}
System.out.println();
c--;
}
}
}
Share article