-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPher.java
49 lines (39 loc) · 1.23 KB
/
Pher.java
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
import java.util.Scanner;
public class Pher {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter size of the arry : ");
int size, searchedid;
size = input.nextInt();
int[] ids = new int[size];
fillarry(ids);
printarry(ids);
System.out.println("Enter the id to search for : ");
searchedid = input.nextInt();
int returnrdindx = search(ids, searchedid);
if (returnrdindx >= 0) {
System.out.println("The item is found");
} else {
System.out.println("The item isn't found...");
}
}
public static void fillarry(int[] list) {
for (int i = 0; i < list.length; i++) {
System.out.println("Enter no " + (i + 1) + ":");
list[i] = input.nextInt();
}
}
public static void printarry(int[] list) {
for (int i = 0; i < list.length; i++) {
System.out.println(list[i]);
}
}
public static int search(int[] list, int target) {
for (int i = 0; i < list.length; i++) {
if (list[i] == target) {
return i;
}
}
return -1;
}
}