Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created September 1, 2015 07:14
Show Gist options
  • Select an option

  • Save jweinst1/d6d9ba4ac4839172b643 to your computer and use it in GitHub Desktop.

Select an option

Save jweinst1/d6d9ba4ac4839172b643 to your computer and use it in GitHub Desktop.
max function implementation in java
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