Here you can find the source of max(int[] arr)
Parameter | Description |
---|---|
arr | An array of integers |
public static int max(int[] arr)
//package com.java2s; //License from project: Apache License public class Main { /**// w ww .j ava 2 s .com * Find max value in an array of integers. * * @param arr An array of integers * @return Max value */ public static int max(int[] arr) { if (arr == null || arr.length == 0) { throw new IllegalArgumentException("Array cannot be null or empty"); } int maxVal = Integer.MIN_VALUE; for (int i : arr) { if (i > maxVal) { maxVal = i; } } return maxVal; } }