TIL/Java

[TIL/Java] 배열 항목에서 최대값 출력하기 (for문 이용)

Namani 2024. 8. 12. 15:20
package practice;

public class MaxArray {

	public static void main(String[] args) {
		int[] array = { 1, 5, 3, 8, 2 };
		int max = -99999;
		for (int index = 0; index < array.length; index++) {
			if (array[index] > max) {
				max = array[index];
			}
		}
		System.out.println(max);
	}
}