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 Regular Falsi Algorithm
Java Program to Check whether Undirected Graph is Connected using DFS
Spring Data JPA and Null Parameters
Java Program to Implement LinkedBlockingDeque API
Apache Commons Collections Bag
Java Program to Implement ConcurrentHashMap API
Hướng dẫn Java Design Pattern – Composite
Java Program to Perform Finite State Automaton based Search
How to Read HTTP Headers in Spring REST Controllers
Spring Boot - Securing Web Applications
How to Get the Last Element of a Stream in Java?
Java Program to Find Maximum Element in an Array using Binary Search
Hướng dẫn Java Design Pattern – Template Method
Java Program to Check if a Given Graph Contain Hamiltonian Cycle or Not
Java 8 – Powerful Comparison with Lambdas
Wrapper Classes in Java
Phương thức tham chiếu trong Java 8 – Method References
Spring Cloud – Adding Angular
Java Program to subtract two large numbers using Linked Lists
Java Program to Implement Sieve Of Eratosthenes
Java Program to Find a Good Feedback Edge Set in a Graph
Java Program to Find the Mode in a Data Set
A Guide to ConcurrentMap
Java Program to Generate Random Hexadecimal Byte
Spring Security and OpenID Connect
Java – Random Long, Float, Integer and Double
Shuffling Collections In Java
Java Program to Implement Sorted Singly Linked List
Java Program to Implement vector
Different Ways to Capture Java Heap Dumps
Check if there is mail waiting
Java Program to Compute the Area of a Triangle Using Determinants