JAVA
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
public class Program
{
public static void main(String[] args) {
int[] a = {1, 2, 4, 4};
System.out.println(paircheck(a, 8));
}
public static boolean paircheck(int[] x, int sum){
int elements = 0;
for(Integer number : x){
elements++;
}
int low = 0;
int hi = elements-1;
while(low<hi){
if(x[low]+x[hi]==sum){
return true;
}
else if(x[low]+x[hi]>sum){
hi++;
}
else if(x[low]+x[hi]<sum){
low++;
}
}
return false;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run