자바 왜 이런 결과가 나오는지 알고 싶습니다.
조회수 500회
import java.util.Scanner;
public class Main {
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
sc.close();
int A = a*2-1;
int K = 1;
int B = a-1;
for(int i =1; i<=A; i++) {
if(i<=a){
for(int k =0; k<K; k++) {
System.out.print("*");
}
}
else {
for(int k=0; k<B; k++) {
System.out.print("*");
}
}
B--;
K++;
System.out.print("\n");
}
}
}
//https://codeup.kr/problem.php?id=1357 이 문제인데 증가하는 별까지는 나오는데 B값이 줄어들어서 별이 감소해야 하는데 감소 하지 않습니다. 왜 그런지 설명 해주시면 감사하겠습니다.
댓글 입력