~22.1.28
Day6
다중 for문의 흐름을 이해하고 기술할 수 있다.
배열을 이해하고 참조 관계를 설명 할 수 있다.
클래스 연동 및 non-static 구현을 이해 할 수 있다.
Create, Read, Update, Delete
[1차원 선언 방법]
datatype 변수명 [] = {element , };
datatype []변수명 = {element, };
datatype []변수명 = new datatype[] {요소 , ,, , };
datatype []변수명 = new datatype[요소크기];
[2차원 선언 방법]
datatype 변수명 [][] = {element , };
datatype [][]변수명 = {element, };
datatype [][]변수명 = new datatype[][] {요소 , ,, , };
datatype [][]변수명 = new datatype[요소크기][];
Day6 WorkShop
public static void for_work4(int[][] res) {
int a, b;
a = 0;
b = 0;
for (int i = res.length - 1; i >= 0; i--) {
for (int j = res.length - 1; j >= 0; j--) {
if (i == j) {
a += res[i][j];
}
}
}
for (int i = 0; i < res.length; i++) {
for (int j = 0; j < res.length; j++) {
if (i == j) {
b += res[i][j];
}
}
}
System.out.println(a + b);
}
public static void for_work5() {
char[][] ar = new char[10][10];
for (int i = 0; i < ar.length; i++) {
for (int j = 0; j < ar.length; j++) {
if ((i >= 1 && i <= 3) || (i >= 5 && i <= 8)) {
ar[i][j] = ' ';
} else {
ar[i][j] = '-';
}
ar[i][0] = '-';
}
}
for (int i = 0; i < ar.length; i++) {
for (int j = 0; j < ar.length; j++) {
System.out.print(ar[i][j] + " ");
}
System.out.println();
}
}
결과물은 아래와 같다
130
- - - - - - - - - -
-
-
-
- - - - - - - - - -
-
-
-
-
- - - - - - - - - -
조금더 깔끔하게 짤수 있을거같은데 아쉽다