Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

24,887 questions

32,502 answers

573 users

How to find the min value in an array in Java

3 Answers

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

 




answered Aug 3, 2021 by avibootz
edited 3 days ago by avibootz
0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int [] {3, 4, 9, 2, 7, 8, 5};   
        
        int min = Arrays.stream(arr).min().getAsInt();
  
        System.out.println(min);
    }
}
  
  
  
  
/*
run:
     
2
     
*/

 




answered 3 days ago by avibootz
0 votes
import java.util.Arrays;
 
public class MyClass {
    public static void main(String args[]) {
        int[] arr = new int [] {3, 4, 9, 2, 7, 8, 5};   
 
        Arrays.sort(arr); 
        
        int min = arr[0];
         
        System.out.println(min);
    }
}
 
 
 
 
/*
run:
    
2
    
*/

 




answered 3 days ago by avibootz
...