21.7.26

Inabang·2021년 7월 26일

PlayData

목록 보기
6/34

~22.1.28

Day6

  1. 다중 for문의 흐름을 이해하고 기술할 수 있다.

  2. 배열을 이해하고 참조 관계를 설명 할 수 있다.

  3. 클래스 연동 및 non-static 구현을 이해 할 수 있다.

  1. CRUD

Create, Read, Update, Delete

  1. Overload (메소드를 선언 할 때 같은 기능의 메소드를 동일한 이름으로 선언하되 () 안에의 매개인자 또는 데이터타입을 다르게 주는 원형)
  1. [1차원 선언 방법]
    datatype 변수명 [] = {element , };
    datatype []변수명 = {element, };

    datatype []변수명 = new datatype[] {요소 , ,, , };
    datatype []변수명 = new datatype[요소크기];

  1. [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
- - - - - - - - - - 
-                   
-                   
-                   
- - - - - - - - - - 
-                   
-                   
-                   
-                   
- - - - - - - - - - 

조금더 깔끔하게 짤수 있을거같은데 아쉽다

0개의 댓글