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:
Adding Shutdown Hooks for JVM Applications
Java Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree
Java Program to Implement Pollard Rho Algorithm
Spring Security Basic Authentication
Jackson – Bidirectional Relationships
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Java Program to Perform Preorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Implement LinkedHashSet API
Calling Stored Procedures from Spring Data JPA Repositories
Spring Boot - Interceptor
Java Program to Represent Graph Using Adjacency Matrix
Spring Data JPA and Null Parameters
Java Program to Implement Queue using Linked List
Spring REST API + OAuth2 + Angular
Use Liquibase to Safely Evolve Your Database Schema
Spring Cloud AWS – EC2
HandlerAdapters in Spring MVC
The DAO with Spring and Hibernate
Stack Memory and Heap Space in Java
Spring Web Annotations
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Convert Hex to ASCII in Java
ETags for REST with Spring
Java Program to Perform Insertion in a BST
Java Program to Represent Graph Using Incidence Matrix
Deploy a Spring Boot App to Azure
New Stream Collectors in Java 9
Java Program to Implement Disjoint Sets
Comparing Objects in Java
Java Program to Implement Hash Tables Chaining with List Heads
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Java Program to Perform LU Decomposition of any Matrix