[Java] - Java 배열 접근 및 출력

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
26
27
28
29
30
package Chapter05;
 
public class MultiDimension {
 
    public static void main(String[] args) {
        int [][] score2 = {
                {1,2,3},
                {4,5,6}
        };
        
        // for문으로 전체출력하기
        
        for(int i=0; i<=1; i++) {
            for(int j=0; j<=2; j++) {
                System.out.println(score2[i][j]);
            }
        }          //이렇게 작성하면 배열의 크기가 달라지면 또 코드를 수정해야하는 불편함이 생김
            
        System.out.println("----------------------");
        for(int h=0; h<score2.length;h++) {
                for(int k=0; k<score2[h].length;k++) {
                    System.out.println(score2[h][k]);
                }
            
        }
        
        }
    }
 
 
cs