Algorithms/Find maximum/Java findMax method 1

From Wikibooks, open books for an open world
Jump to: navigation, search

Code Java

  public int findMax(final int[] i_intaryTab) {
    if ( i_intaryTab.length == 1)
       return i_intaryTab[0];
    else if ( i_intaryTab.length == 0 ) )
       return 0;
    int o_intMax = i_intaryTab[0];
    for ( int p_intI = 1; p_intI < i_intaryTab.length; p_intI++)
        if ( i_intaryTab[p_intI] > o_intMax )
           o_intMax = i_intaryTab[p_intI];
    return o_intMax;
  } // end method