Java Program to find the minimum element in an array
Problem Description
Write a Java Program to find the minimum element in an array. We will declare an array with some numbers. Loop each element in the array to find the minimum element in the given array.
Java Program
//******************************** //MinInArray.java //******************************** public class MinInArray { //main method public static void main(String[] args) { int minValue= Integer.MAX_VALUE; int[] arr = {2, 6, 18, 9, 56, 44, 63, 22, 76, 28}; // declare an array of numbers for (int i = 0; i < arr.length; i++) { if(arr[i] < minValue) { minValue = arr[i]; } } System.out.print("The minimum element in the array is= " + minValue); //output min number } }
Program Output
The minimum element in the array is= 2
Screenshot
—
Java Tutorial on this website: https://www.testingdocs.com/java-tutorial/
For more information on Java, visit the official website :