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:
Converting Between an Array and a Set in Java
Java Program to Solve the Fractional Knapsack Problem
Convert String to Byte Array and Reverse in Java
Java Program to Implement Fisher-Yates Algorithm for Array Shuffling
Dynamic Proxies in Java
Quick Guide to Spring MVC with Velocity
Hướng dẫn Java Design Pattern – Mediator
Java Program to Solve the 0-1 Knapsack Problem
Redirect to Different Pages after Login with Spring Security
A Guide to the ResourceBundle
Giới thiệu về Stream API trong Java 8
Java Program to Implement Bucket Sort
How to Return 404 with Spring WebFlux
Java Timer
Get and Post Lists of Objects with RestTemplate
Extract network card address
Java Program to Represent Linear Equations in Matrix Form
REST Web service: Basic Authentication trong Jersey 2.x
Introduction to Using Thymeleaf in Spring
Hamcrest Collections Cookbook
Java Program to Describe the Representation of Graph using Adjacency Matrix
Implementing a Binary Tree in Java
Custom Error Pages with Spring MVC
Rate Limiting in Spring Cloud Netflix Zuul
Spring Boot - Build Systems
Logging in Spring Boot
Java Program for Douglas-Peucker Algorithm Implementation
Use Liquibase to Safely Evolve Your Database Schema
Java Program to Implement Ternary Heap
Lớp HashMap trong Java
Spring Cloud – Adding Angular
Guide to the Fork/Join Framework in Java