Image

Programs - Java - Core Java - Array

Program:


class AnonArray {
  public static void main(String[] args) {
    System.out.println("Minimum value: " +
         findMinimum(new int[] {3, 5, 2, 8, 6}));      // (1)
  }

  public static int findMinimum(int[] dataSeq) {          // (2)
    // Assume the array has at least one element.
    int min = dataSeq[0];
    for (int index = 1; index < dataSeq.length; ++index)
      if (dataSeq[index] < min)
        min = dataSeq[index];
    return min;
  }
}