Here you can find the source of arrayMaximum(int[] array)
Parameter | Description |
---|---|
array | of ints |
Parameter | Description |
---|---|
NoSuchElementException | if you give it an empty or null array |
public static int arrayMaximum(int[] array)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/* w ww . j a va 2s . c o m*/ * * @param array of ints * @return An integer which is equal to the largest element in the array * @throws NoSuchElementException if you give it an empty or null array */ public static int arrayMaximum(int[] array) { if ((array == null) || (array.length == 0)) { throw new NoSuchElementException(); } int q = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] > q) { q = array[i]; } } return q; } }