# 배열 활용

1. 배열의 요소 중에서 최대값과 최소값 찾기

```java
class Ex5_3 { 
	public static void main(String[] args) { 
		int[] score = { 79, 88, 91, 33, 100, 55, 95 }; 

		int max = score[0]; 
		int min = score[0]; 

		for(int i=1; i < score.length;i++) {
			if(score[i] > max) { 
				max = score[i]; 
			} else if(score[i] < min) { 
				min = score[i]; 
			} 
		} // end of for 

		System.out.println("최대 :" + max);       
		System.out.println("최소 :" + min);       
	} // end of main 
} // end of class
```

2\. shuffle(섞기) : 숫자 섞기, 로또번호 생성

```java
class lottery {
	public static void main(String[] args) {
		int[] ball = new int[45];//45개의 정수값을 저장하기 위한 int타입의 배열을 만들어준다.
		
		//배열의 각 요소에 1~45의 값을 저장한다.
		for(int i=0; i < ball.length; i++) {
			ball[i] = i+1;
		}
		
		int tmp = 0;
		int index = 0;
		
		//6개의 로터리 번호를 생성해보자!
		for(int i=0; i < 6;i++) {
//			index = Math.random()*(ball.length);
			index = (int)(Math.random()*45);//배열의 index인 0부터 44사이의 랜덤한 수 생성!
			tmp = ball[i];
			ball[i] = ball[index];
			ball[index] = tmp;
		}
		
		for(int i = 0; i <6;i++) {
			System.out.printf("ball[%d] = %d%n",i,ball[i]);
		}
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/java/ch5/undefined.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
