Skip to content

Instantly share code, notes, and snippets.

@NusZzz
Created December 24, 2013 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NusZzz/8115140 to your computer and use it in GitHub Desktop.
Save NusZzz/8115140 to your computer and use it in GitHub Desktop.
The example of finding maximum number in Array (java)
public class Hello {
public static void main(String[] args) {
int[] array = new int[]{3,7,4,9,5,6,8,1,20,2};
int largest = FindMax(array, 1, 20);
System.out.print("The largest value = "+largest);
}
public static int FindMax(int[] a, int start, int largest) {
if (start == a.length)
return largest;
else {
int last = (a[start] > largest ? a[start] : largest);
return FindMax(a, start + 1, last);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment