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 Number of Articulation points in a Graph
Java Program to Implement Queue using Two Stacks
Java Program to Implement Extended Euclid Algorithm
Giới thiệu Swagger – Công cụ document cho RESTfull APIs
Spring Data Reactive Repositories with MongoDB
Java Program to Implement Merge Sort on n Numbers Without tail-recursion
Sorting in Java
Binary Numbers in Java
DistinctBy in the Java Stream API
Using the Map.Entry Java Class
Chương trình Java đầu tiên
Java 8 – Powerful Comparison with Lambdas
Debug a JavaMail Program
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Java Program to Implement Fenwick Tree
Call Methods at Runtime Using Java Reflection
Java Program to Implement Disjoint Set Data Structure
Java Program to Implement Hash Tables Chaining with List Heads
Java Program to Perform the Shaker Sort
Introduction to the Java NIO2 File API
Introduction to Spring Security Expressions
Inject Parameters into JUnit Jupiter Unit Tests
Hướng dẫn sử dụng Java String, StringBuffer và StringBuilder
A Comparison Between Spring and Spring Boot
Java Program to Check if a Given Graph Contain Hamiltonian Cycle or Not
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
LinkedHashSet trong Java hoạt động như thế nào?
Java Program to Generate Random Numbers Using Multiply with Carry Method
Java Program to Implement TreeSet API
Spring 5 Testing with @EnabledIf Annotation
Optional trong Java 8
Spring Boot - OAuth2 with JWT