-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearSearch.java
More file actions
28 lines (27 loc) · 832 Bytes
/
linearSearch.java
File metadata and controls
28 lines (27 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class linearSearch {
public static int LinearSearch(int numbers[] ,int key ){
for (int i=0;i< numbers.length ;i++){//code to find the position of 10
if (numbers [i]==key){
return i;
}
}
return -1;
}
public static int LinearSearch(String Dishes[],String b) {
for (int i = 0; i < Dishes.length;i++){
if (Dishes[i] == b) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
int numbers[]= {2,4,6,8,10,12,};
String Dishes[]={"Dhosa", "Vada", "Shambhar"};
String key1="Vada";
int key=10;
System.out.println(LinearSearch(numbers,key));
System.out.println(LinearSearch(Dishes,key1));
}
}