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 Stack using Linked List
Kiểu dữ liệu Ngày Giờ (Date Time) trong java
Using the Map.Entry Java Class
Encode a String to UTF-8 in Java
Use Liquibase to Safely Evolve Your Database Schema
Java Program to Implement AttributeList API
Tạo ứng dụng Java RESTful Client không sử dụng 3rd party libraries
Spring Security Registration – Resend Verification Email
Java Program to Find Basis and Dimension of a Matrix
Java Program to Implement Tarjan Algorithm
Implementing a Runnable vs Extending a Thread
Java Program to Perform Partial Key Search in a K-D Tree
Creating Docker Images with Spring Boot
Java Program to Implement Gauss Jordan Elimination
Guava – Join and Split Collections
Comparing Objects in Java
Guava Collections Cookbook
The “final” Keyword in Java
Introduction to Java Serialization
Java – Byte Array to Reader
Exploring the New Spring Cloud Gateway
Tạo chương trình Java đầu tiên sử dụng Eclipse
Spring NoSuchBeanDefinitionException
Từ khóa static và final trong java
Java Program to Implement Self Balancing Binary Search Tree
Java Program to Perform Searching in a 2-Dimension K-D Tree
Java Program to Implement Find all Cross Edges in a Graph
Sao chép các phần tử của một mảng sang mảng khác như thế nào?
Introduction to Using Thymeleaf in Spring
Java Program to Implement First Fit Decreasing for 1-D Objects and M Bins
Java Program to Implement HashSet API
JUnit 5 for Kotlin Developers