Created
September 1, 2015 07:14
-
-
Save jweinst1/d6d9ba4ac4839172b643 to your computer and use it in GitHub Desktop.
max function implementation in java
This file contains hidden or 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
| import java.util.Arrays; | |
| class Main { | |
| public static void main(String[] args) { | |
| System.out.println(maxval(lst)); | |
| } | |
| static int[] lst = {1, 2, 3}; | |
| static int maxval(int[] x) { | |
| int size = x.length; | |
| int counter = 0; | |
| int current = x[0]; | |
| while (counter <= size) { | |
| if (counter == size) { | |
| return current; | |
| } else { | |
| if (current > x[counter + 1]) { | |
| counter ++; | |
| } else { | |
| current = x[counter]; | |
| counter ++; | |
| } | |
| } | |
| } | |
| return current; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment