728x90
SMALL
public class Sample4 {
public static void main(String[] args) {
int sum = 0;
int count = 1;
int[][] a = new int[5][5];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
a[i][j] = count;
count ++;
System.out.printf("%4d" ,a[i][j]);
}
System.out.println(" ");
}
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a.length; j++) {
if (i== 0 || i ==4|| j==0 || j ==4) {
sum += a[i][j];
System.out.println(a[i][j]);
}
}
}
System.out.println(sum);
}
}
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
208
728x90
LIST
'JAVA > Java' 카테고리의 다른 글
20201015_16 (0) | 2020.10.15 |
---|---|
20201015_16 업캐스팅, try -catch, 스레드 (0) | 2020.10.15 |
20201014_15 AWT로 작성한 GUI프로그램 (0) | 2020.10.14 |
20201014_15 OSI 7계층, interface (0) | 2020.10.14 |
20201013_14 Arraylist이용한 학생정보 프로그램 (0) | 2020.10.13 |
댓글