Tuesday 1 January 2013

How to find the minimum and the maximum element in an array

import java.util.Arrays;
import java.util.Collections;

public class Main3 {
   public static void main(String[] args) {
      Integer[] numbers = { 8, 2, 7, 15, 4, 9, 5,99};
      int min = (int) Collections.min(Arrays.asList(numbers));
      int max = (int) Collections.max(Arrays.asList(numbers));
      System.out.println("Min number: " + min);
      System.out.println("Max number: " + max);
   }
}

No comments:

Post a Comment

What is Map Collection?

A map collection refers to a set of maps that are compiled and organized for a specific purpose, such as research, education, or preservatio...