2번 참조 타입 변수의 메모리 생성 위치는 스택이다.
메모리 생성 위치는 힙임
3번 참조되지 않는 객체는 프로그램에서 직접 소멸 코드를 작성하는 것이 좋다.
개발자가 직접 객체를 없애는 코드는 없는 대신, 가비지 컬렉터가 사용하지 않는 객체를 제거한다.
2번 String 타입의 문자열 비교는 ==를 사용해야 한다.
==를 사용하면 메모리 번지를 비교하게 된다. equals 메소드를 이용해야 한다.
+ String은 클래스 타입
2번 int[] array; array = {1, 2, 3};
3번 실수 타입 배열 항목의 기본 초기값은 true이다.
false임
3 (array.length는 첫번째 차원의 길이를 출력함)
5
int[] array = {1, 5, 3, 8, 2};
int top;
top = array[0];
for(int i = 1; i < array.length; i++) {
if(top < array[i])
top = array[i];
}
System.out.print(top);
int[][] array = {{95, 86}, {83, 92, 96}, {78, 83, 93, 87, 88}};
int sum = 0;
int count = 0;
for(int i = 0; i < array.length; i++) {
for(int j = 0; j < array[i].length; j++) {
sum += array[i][j];
count++;
}
}
double avg = (double)sum / count;
System.out.println(sum);
System.out.println(avg);
Scanner sc = new Scanner(System.in);
boolean run = true;
int stunum = 0;
int[] scores = null;
while(run) {
System.out.println("---------------------------------------------------------");
System.out.println("1. 학생수 | 2. 점수 입력 | 3. 점수리스트 | 4. 분석 | 5. 종료");
System.out.println("---------------------------------------------------------");
System.out.print("선택>");
int choice = sc.nextInt();
switch(choice) {
case 1:
System.out.print("학생수>");
stunum = sc.nextInt();
scores = new int[stunum];
for (int i = 0; i < stunum; i++) {
scores[i] = 0;
}
break;
case 2:
for(int i = 0; i < stunum; i++) {
System.out.printf("scores[%d]>", i);
scores[i] = sc.nextInt();
}
break;
case 3:
for(int i = 0; i < stunum; i++) {
System.out.printf("scores[%d]: %d\n", i, scores[i]);
}
break;
case 4:
int top;
top = scores[0];
for(int i = 1; i < scores.length; i++) {
if(top < scores[i])
top = scores[i];
}
System.out.printf("최고 점수: %d\n", top);
int sum = 0;
int count = 0;
for(int i = 0; i < scores.length; i++) {
sum += scores[i];
count++;
}
double avg = (double)sum / count;
System.out.printf("평균 점수: %4.1f\n", avg);
break;
case 5:
System.out.print("프로그램 종료");
run = false;
break;
}
}