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 Implement Hash Trie
Java Program to Implement Insertion Sort
The Registration Process With Spring Security
Read an Outlook MSG file
Java Program to Compute Discrete Fourier Transform Using Naive Approach
Create a Custom Exception in Java
Java Program to Represent Graph Using Incidence Matrix
Converting Between an Array and a Set in Java
Từ khóa throw và throws trong Java
Spring Security Registration – Resend Verification Email
Extra Login Fields with Spring Security
@Lookup Annotation in Spring
Java Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range
Java Program to Check whether Directed Graph is Connected using BFS
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
JWT – Token-based Authentication trong Jersey 2.x
Java Program to Implement ConcurrentLinkedQueue API
Java Program to Generate a Graph for a Given Fixed Degree Sequence
Concrete Class in Java
XML-Based Injection in Spring
So sánh HashSet, LinkedHashSet và TreeSet trong Java
Spring Data MongoDB – Indexes, Annotations and Converters
Jackson Unmarshalling JSON with Unknown Properties
Java 8 Stream findFirst() vs. findAny()
Sử dụng CyclicBarrier trong Java
Java Program to Implement Circular Singly Linked List
Semaphore trong Java
Bootstrapping Hibernate 5 with Spring
Java Program to Implement Euclid GCD Algorithm
LinkedHashSet trong Java hoạt động như thế nào?
HashMap trong Java hoạt động như thế nào?
Java Program to Generate All Pairs of Subsets Whose Union Make the Set