This repository was archived by the owner on Sep 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExamples.java
More file actions
59 lines (49 loc) · 1.4 KB
/
Copy pathArrayExamples.java
File metadata and controls
59 lines (49 loc) · 1.4 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class ArrayExamples {
public static void main(String args[]) {
int[] first = {1,2,3,4,5,6,7,8,9,10};
System.out.println(slice(first, 2,5)[0]);
System.out.println(slice(first, 2,5)[1]);
System.out.println(slice(first, 2,5)[2]);
System.out.println(slice(first, 2,5)[3]);
}
public static int numPassing(int[] A, int passingScore) {
int count=0;
for (int i=0; i<A.length; i++) {
if(A[i]>passingScore) {
count++;
}
}
return count;
}
public static boolean reverses(int[] A) {
int[] B = new int[A.length];
for (int i=A.length-1,j=0; i>=0; i--,j++) {
B[j] = A[i];
}
for (int i=0;i<A.length;i++) {
if(B[i]!=A[i]) {
return false;
}
}
return true;
}
public static boolean same(int[] A, int[] B) {
return A.equals(B);
}
public static int[] copy(int[] A) {
int[] B = new int[A.length];
for (int i = 0; i<A.length; i++) {
B[i] = A[i];
}
return B;
}
public static int[] slice(int[] A, int i, int j) {
int[] B = new int[j-i+1];
for (int start = i, z=0; start<=j; start++,z++) {
B[z] = A[start];
}
return B;
}
}