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 Word Wrap Problem
Spring Boot - Unit Test Cases
Rate Limiting in Spring Cloud Netflix Zuul
Java Program to Implement ScapeGoat Tree
Returning Image/Media Data with Spring MVC
Giới thiệu Java Service Provider Interface (SPI) – Tạo các ứng dụng Java dễ mở rộng
So sánh ArrayList và Vector trong Java
Lớp Collections trong Java (Collections Utility Class)
Java Program to Implement RenderingHints API
Tính kế thừa (Inheritance) trong java
Spring Data Java 8 Support
Converting String to Stream of chars
Mệnh đề Switch-case trong java
Java Convenience Factory Methods for Collections
Java Program to Implement Find all Forward Edges in a Graph
Java Program to Implement Vector API
Validate email address exists or not by Java Code
Java Program to Implement Efficient O(log n) Fibonacci generator
Hướng dẫn Java Design Pattern – Bridge
Introduction to Spring Data MongoDB
Java Program to Compute the Area of a Triangle Using Determinants
Java Program to Perform Left Rotation on a Binary Search Tree
Java Program to Implement ArrayDeque API
Spring Cloud AWS – EC2
Java Program to Perform Postorder Recursive Traversal of a Given Binary Tree
Java Program to Check Whether Graph is DAG
Netflix Archaius with Various Database Configurations
Mockito and JUnit 5 – Using ExtendWith
Java TreeMap vs HashMap
Hướng dẫn Java Design Pattern – Mediator
Java Program to Implement Interval Tree
Serialize Only Fields that meet a Custom Criteria with Jackson