-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_test.java
More file actions
55 lines (38 loc) · 1 KB
/
Copy pathArray_test.java
File metadata and controls
55 lines (38 loc) · 1 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
import javax.naming.spi.Resolver;
public class Array_test {
public static void main(String[] args){
int[] arr={1,2,3,5,55};
//arr = null;
System.out.println(arr[3]);
for(int x=0;x<arr.length;x++){
System.out.println(arr[x]);
}
int[] arr2 = {3,4,5,66,2,44,5234,2,333,44,55};
printArray(arr2);
System.out.println("arr is no reverse###############");
reverse(arr2);
printArray(arr2);
System.out.println("####################");
System.out.println(getIndex(arr2, 44));
}
public static void printArray(int[] arr) {
for(int x=0;x<arr.length;x++){
System.out.println(arr[x]);
}
}
public static void reverse(int[] arr){
for(int x=0;x<arr.length/2;x++){
int temp = arr[x];
arr[x] = arr[arr.length-1-x];
arr[arr.length-1-x] = temp;
}
}
public static int getIndex(int[] arr,int value){
for(int x=0;x<arr.length;x++){
if(arr[x] == value){
return x;
}
}
return -1;
}
}