[Java] Integer.MIN_VALUE & Integer.MAX_VALUE/배열 초기화/배열 접근

hameee·2023년 9월 25일
0

Java

목록 보기
10/26
post-thumbnail

📍 Integer.MIN_VALUE & Integer.MAX_VALUE

  • Integer.MIN_VALUE: int 데이터 타입이 나타낼 수 있는 가장 작은 정수값
  • Integer.MAX_VALUE: int 데이터 타입이 나타낼 수 있는 가장 큰 정수값
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println(Integer.MAX_VALUE); // 2147483647

📍 배열 초기화

방법1) 배열 선언 후 값 할당

int[] scores = {10, 20, 30, 40, 50};

방법2) 배열 크기 지정 후 값 할당

int[] scores = new int[5];
scores[0] = 10;
scores[1] = 20;
scores[2] = 30;
scores[3] = 40;
scores[4] = 50;

📍 배열 접근

인덱스를 통해 배열 요소에 접근한다. 배열 자체에 직접 접근할 수는 없다. 배열 자체를 출력하려고 하면 hash값이 출력된다.

int[] numbers = {1, 2, 3};
System.out.println(numbers[0]); // 1
System.out.println(numbers); // [I@387c703b

0개의 댓글