[Solved] Java: Finding the smallest greater than zero number in an array


public static int findSmallest(int[] arr) {
    int smallest = Integer.MAX_VALUE;
    for(int i=0; i<arr.length; i++) {
        if(arr[i] > 0 && arr[i]<smallest) {
            smallest = arr[i];
        }
    }
    return smallest;
}

At the end, if smallest == Integer.MAX_VALUE, then all the array is filled of zeros.

4

solved Java: Finding the smallest greater than zero number in an array