//[?] 주어진 데이터 중에서 가장 큰 값 구하기
/**
* 최댓값 알고리즘(Max Algorithm): (주어진 범위 + 주어진 조건)의 자료들의 가장 큰 값
*/
public class MaxAlgorithm2 {
public static void main(String[] args) {
int max = Integer.MIN_VALUE; // Initilize 초기화 | 정수 형식의 데이터 중 가장 작은 값으로 초기화 ***
int[] numbers = { -2, -5, -3, -7, -1 };
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i]; // MAX: 더 큰 값으로 할당
}
}
System.out.println("최댓값:" + max);
}
}
출력값: 최댓값:-1
'Dev > Java' 카테고리의 다른 글
6. 근삿값 알고리즘 (Near Algorithm) (0) | 2022.08.08 |
---|---|
5. 최솟값 알고리즘 (Min Algorithm) (0) | 2022.08.08 |
3. 평균 알고리즘(Average Algorithm) (0) | 2022.08.08 |
2. 개수 알고리즘(Count Algorithm) (0) | 2022.08.08 |
1-1. 등차수열(Arithmetic Sequence) (0) | 2022.08.08 |
댓글