Notice
Recent Posts
Recent Comments
Link
HwangHub
[Java] 배열 선언시 초기화 본문
자바에서는 배열을 선언하게 되면, 자동으로 초기값이 0으로 채워지게 된다.
public static void main(String[] args) {
int[] arr = new int[5];
for (int i = 0; i < 5; i++) {
System.out.print(arr[i] + " ");
}
System.out.println("\n-------------------");
int[][] matrix = new int[5][5];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
위 코드를 실행한 결과는 아래와 같다.
0 0 0 0 0
------------
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
'workspace > 아티클' 카테고리의 다른 글
[Java] 숫자 character의 아스키 코드 (0) | 2023.07.01 |
---|---|
[Java] 문자열의 .charAt(), .length() 메서드 (0) | 2023.06.30 |
[JPA] Data JPA 기초 (0) | 2023.06.30 |
[JPA] OSIV (0) | 2023.06.28 |
[JPA] 연관관계 컬렉션 필드 조회 최적화 : 엔티티/DTO 조회 방식 (0) | 2023.06.28 |
Comments