How to find the smallest value in array with Java

1 Answer

0 votes
public class Test {  
    public static void main(String[] args) {  
        int arr[] = {3, 4, 9, 6, 7, 1, 2, 5};
        
        int len = arr.length;
        int min ;
         
        min = Integer.MAX_VALUE;
  
        for (int i = 0; i < len; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println(min);
    }  
}  
 
  
  
  
/*
run:
  
1

*/

 



answered Apr 1, 2021 by avibootz

Related questions

...