-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfindKey
57 lines (52 loc) · 1.69 KB
/
findKey
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package Arrays;
import java.util.*;
public class arraysQ {
// public static void main(String args[]) {
// int marks[] = new int[100];
// Scanner sc = new Scanner(System.in);
// // marks[0] = sc.nextInt();
// // marks[1] = sc.nextInt();
// // marks[2] = sc.nextInt();
// // int percentage = (marks[0] + marks[1] + marks[2])/3;
// // System.err.println("Percentage is " + percentage + "% " );
// System.out.println(" length of array "+ marks.length);
// }
//
// public static int linearSearch(int numbers[], int key) {
// for(int i=0; i<numbers.length; i++ ){
// if(numbers[i] == key) {
// return i;
// }
// }
// return-1;
// }
// public static void main(String args[]) {
// int numbers[] = {2,4,6,8,10,12,14,18};
// int key = 22;
// int index = linearSearch(numbers, key);
// if(index==-1) {
// System.out.println("Not Found");
// }
// else{
// System.out.println("Key is at index " + index);
// }
// }
public static String dishSearch(String menu[] ,String dish ) {
for(int i=0; i<menu.length; i++) {
if(menu[i] == dish) {
return "1";
}
}
return "-1";
}
public static void main (String args[]) {
String menu[] = {"Dosa" , "Chole Bhature" , "Chowmein", "Pizza", "Burger"};
String dish = "Samosa";
String index = dishSearch(menu, dish);
if(index=="-1") {
System.out.println("Not Found");
}else {
System.out.println( index);
}
}
}