From 5a25bd346606b3186386eb8ae4989d1553dd71ba Mon Sep 17 00:00:00 2001 From: sal81 Date: Thu, 21 Jan 2021 05:17:01 +0530 Subject: [PATCH] Add java code for linear search --- searching/README.md | 6 ++++++ searching/java/linear-search.java | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 searching/java/linear-search.java diff --git a/searching/README.md b/searching/README.md index 445b9284..66b19622 100644 --- a/searching/README.md +++ b/searching/README.md @@ -11,3 +11,9 @@ 1. [Linear Search](python/linear-search.py) 2. [Binary Search](python/binary-search.py) +### Java + +1. [Linear Search](java/linear-search.java) + + + diff --git a/searching/java/linear-search.java b/searching/java/linear-search.java new file mode 100644 index 00000000..4c8e2d3b --- /dev/null +++ b/searching/java/linear-search.java @@ -0,0 +1,21 @@ +//Linear search to check for a given key in an array + +public class MyLinearSearch{ +public static int linearSearch(int[] arr, int key){ + for(int i=0;i followed by +//It will generate and a MyLinearSearch.class file which is a file containing java bytecode that is executed by JVM.