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 Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
How to Return 404 with Spring WebFlux
TreeSet và sử dụng Comparable, Comparator trong java
Java Program to Generate All Possible Combinations of a Given List of Numbers
Guide to Spring @Autowired
Hướng dẫn sử dụng luồng vào ra nhị phân trong Java
Spring Boot - Eureka Server
Giới thiệu Google Guice – Binding
Daemon Threads in Java
Introduction to Netflix Archaius with Spring Cloud
Returning Image/Media Data with Spring MVC
The Difference Between Collection.stream().forEach() and Collection.forEach()
Examine the internal DNS cache
Spring Boot Annotations
A Guide to Queries in Spring Data MongoDB
Java Program to Implement Segment Tree
An Intro to Spring Cloud Contract
Summing Numbers with Java Streams
Tiêu chuẩn coding trong Java (Coding Standards)
Guide to the Volatile Keyword in Java
Anonymous Classes in Java
Java Program to Implement HashTable API
Immutable ArrayList in Java
Hướng dẫn Java Design Pattern – Prototype
Java Program to Perform the Unique Factorization of a Given Number
Java Program to Implement Gabow Algorithm
Guide to BufferedReader
Spring Boot Tutorial – Bootstrap a Simple Application
Login For a Spring Web App – Error Handling and Localization
A Guide to Iterator in Java
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Check if an UnDirected Graph is a Tree or Not Using DFS