카테고리 없음
알파벳 마름모
추억을 백앤드하자
2021. 1. 12. 14:22
728x90
반응형
SMALL
알파벳 순서대로 다음과 같이 모래시계 모양대로 출력하는
코드를 작성하여 출력하시오
<결과화면>
import java.util.ArrayList;
import java.util.Scanner;
public class test5 {
public static void main(String[] args) {
int array[][] = new int[5][5];
char ch = 'A';
for (int i = 0; i <=4; i++) {//행 0~4
if(i<=2) { //행이2이하이면
for (int j = i; j <=4-i; j++) {//열
array[i][j]=ch++;
}
}else{ //행이 2초과이면
for (int j = 4-i; j <=i; j++) {//열
array[i][j]=ch++;
}
}
}
//출력문
for (int i = 0; i <=4; i++) {
for (int j = 0; j <=4; j++) {
System.out.printf("%c",array[i][j]);
}
System.out.println();
}
}
}
728x90
반응형
LIST