Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
Add Java Linear Search-13(#181)
Browse files Browse the repository at this point in the history
Related to #1
  • Loading branch information
Janitha133 authored and ayan-b committed Oct 20, 2019
1 parent c22d0b4 commit 1d9861c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Linear search is a very simple search algorithm. In this type of search, a seque
|37| [Ryan Smolik](https://github.com/ryansmolik03) | | |Java|
|38| [Ciaran Evans](https://github.com/ciaranevans) | | UK | Lua |
|39| [Balakumaran](https://github.com/webbalakumaran) | | India | Julia
|40| [Janitha](https://github.com/janitha133) | | Sri Lanka | Java
24 changes: 24 additions & 0 deletions java-linear-search/java-linear-search-13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.Scanner;

public class LinearSearch {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int value = input.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = input.nextInt();
}
linearSearch(n, array, value);
}

private static void linearSearch(int n, int[] array, int value) {
for (int i = 0; i < n; i++) {
if (array[i] == value) {
System.out.println(i);
return;
}
}
System.out.println("Not Found!");
}
}

0 comments on commit 1d9861c

Please sign in to comment.