-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrayHandler.java
44 lines (35 loc) · 1.14 KB
/
ArrayHandler.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
package array;
public class ArrayHandler {
public boolean contains(int[] source, int itemToFind) {
for (int item : source) {
if (item == itemToFind) {
return true;
}
}
return false;
}
public int find(int[] source, int itemToFind) {
for (int i = 0; i < source.length; i++) {
if (source[i] == itemToFind) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
ArrayHandler arrayHandler = new ArrayHandler();
final int[] testArray = new int[]{1, 3, 5, 10};
System.out.println(
"Tartalmazza a következő értékeket?\n8: "
+ arrayHandler.contains(testArray, 8)
+ "\n5: "
+ arrayHandler.contains(testArray, 5)
);
System.out.println(
"Hányadik pozícióban van az alább érték?\n8: "
+ arrayHandler.find(testArray, 8)
+ "\n5: "
+ arrayHandler.find(testArray, 5)
);
}
}