-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathArrayDemo.java
More file actions
63 lines (56 loc) · 1.64 KB
/
Copy pathArrayDemo.java
File metadata and controls
63 lines (56 loc) · 1.64 KB
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
58
59
60
61
62
63
/*
* Created by IntelliJ IDEA.
* User: divyanshb
* Date: 08/01/20
* Time: 3:46 PM
*/
package array;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
/*
for (int i = 0; i < integers.length; i++) {
System.out.print(integers[i] + ", ");
}
*/
/*for (int i : integers) {
System.out.print(i + ", ");
}*/
int[] integers = new int[10];
printArrayValues(integers);
// initialiseIntegerArray(integers);
/*printArrayValues(integers);
boolean response = searchInArray(integers, 22);
if (response) {
System.out.println("Value found!");
} else {
System.out.println("Value not found");
}
System.out.println(response ? "value found" : "not found");*/
}
/**
* This method can search a integer value in an integer array.
*
* @param array an integer array
* @param value the value to be searched
* @return True if the value if found in the array
*/
public static boolean searchInArray(int[] array, int value) {
boolean response = false;
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
response = true;
break;
}
}
return response;
}
public static void printArrayValues(int[] integers) {
System.out.println(Arrays.toString(integers));
}
public static void initialiseIntegerArray(int[] integerArray) {
for (int i = 0; i < integerArray.length; i++) {
integerArray[i] = (i + 1);
}
}
}