Created
December 24, 2013 16:05
-
-
Save NusZzz/8115140 to your computer and use it in GitHub Desktop.
The example of finding maximum number in Array (java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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