get Mini Positive Number - Android java.lang

Android examples for java.lang:Integer

Description

get Mini Positive Number

Demo Code

import java.util.Arrays;

public class Main {

  public static int getMiniPositiveNum(int... num) {
    if (num == null || num.length == 0) {
      return -1;//from  w w w.  j  av a2s .c  o m
    }

    int result = -1;

    Arrays.sort(num);

    for (int i = 0; i < num.length; i++) {
      if (num[i] >= 0) {
        result = num[i];
        break;
      }
    }

    return result;
  }

}

Related Tutorials