Java program to find minimum value in array

In this tutorial, Java program to find minimum value in an array.
Here is simple algorithm to find minimum value in the array.

  • Initialize sml with arr[0] i.e. first element in the array.
  • If current element is less than sml, then set sml to current element.
import java.util.Scanner;

public class Finder
{
   public static void main(String args[])
   {
       int sml, size, i;
       int numArr[] = new int[50];
       Scanner scan = new Scanner(System.in);

       System.out.print("Enter array Size : ");
       size = scan.nextInt();

       System.out.print("Enter array elements : ");
       for(i=0; i<size; i++){
           numArr[i] = scan.nextInt();
       }

       System.out.print("Searching for the Smallest Element....\n\n");

       sml = numArr[0];

       for(i=0; i<size; i++){ 
           if(sml > numArr[i]){
               sml = numArr[i];
           }

       }

       System.out.print("Smallest Element = " + sml); 
   }
}

Output:

Enter array Size : 3
Enter array elements : 45 76 35
Searching for the Smallest Element….Smallest Element = 35

That’s all about Java program to find minimum value in an array

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.