Java Program to Find Minimum Element in an Array using Linear Search

This is a java program to find the minimum element of the sequence using the technique of linear search. First we assign min equal to the first element of the sequence, then we go on exploring each element of the sequence and compare it with the min element, if less we update min.

Here is the source code of the Java Program to Find Minimum Element in an Array using Linear Search. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

//This is a java program to find the minimum element using the technique of Sequential Search
import java.util.Random;
import java.util.Scanner;
 
public class Minimum_Using_Sequential 
{
    static int N = 20;
    static int []sequence = new int[N];
 
    public static int minSequential()
    {
        int min = sequence[0];
        for(int i=0; i<N; i++)
            if(min > sequence[i])
                min = sequence[i];
 
        return min;
    }
    public static void main(String args[])
    {
        Random random = new Random();
 
        for(int i=0; i<N; i++)
            sequence[i] = Math.abs(random.nextInt(100));
        System.out.println("The sequence is :");
        for(int i=0; i<N; i++)
            System.out.print(sequence[i] + " ");     
 
        Scanner sc = new Scanner(System.in);
        System.out.println("\nThe minimum element in the sequence is : " + minSequential());
        sc.close();
    }
}

Output:

$ javac Minimum_Using_Sequential.java
$ java Minimum_Using_Sequential
 
The sequence is :
33 43 61 93 97 31 53 62 58 87 68 61 16 52 12 29 27 63 68 22 
The minimum element in the sequence is : 12

Related posts:

Java Program to Generate a Graph for a Given Fixed Degree Sequence
Tiêu chuẩn coding trong Java (Coding Standards)
Java Program to Implement Circular Doubly Linked List
A Quick Guide to Spring Cloud Consul
Working with Tree Model Nodes in Jackson
Java Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
Java Program to Implement Best-First Search
Constructor Dependency Injection in Spring
Command-Line Arguments in Java
New in Spring Security OAuth2 – Verify Claims
Ép kiểu trong Java (Type casting)
A Custom Media Type for a Spring REST API
Custom HTTP Header with the HttpClient
The Guide to RestTemplate
Java Program to Implement Johnson’s Algorithm
HashMap trong Java hoạt động như thế nào?
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Các kiểu dữ liệu trong java
REST Web service: Basic Authentication trong Jersey 2.x
Java Program to Perform Encoding of a Message Using Matrix Multiplication
Java Program to Represent Linear Equations in Matrix Form
Java Program to Check Cycle in a Graph using Graph traversal
A Guide to Concurrent Queues in Java
Java Program to Perform Naive String Matching
Java Program to find the maximum subarray sum using Binary Search approach
Mapping Nested Values with Jackson
Handle EML file with JavaMail
Java Program to Implement Hash Tables chaining with Singly Linked Lists
Sao chép các phần tử của một mảng sang mảng khác như thế nào?
Java Program to Implement Depth-limited Search
Transaction Propagation and Isolation in Spring @Transactional
Guide to Guava Multimap