jweinst1
9/1/2015 - 7:14 AM

max function implementation in java

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;
  }
}