package chatpter6;
import java.util.Arrays;
public class num1 {
boolean hasSum(int[] A,int target){
boolean res = false;
Arrays.sort(A);
int i = 0,j = A.length-1;
while(i<j){
if(A[i] + A[j] == target){
res = true;
return res;
}else if(A[i] + A[j] < target){
i++;
}else if(A[i] + A[j] > target){
j--;
}
}
return res;
}
public static void main(String[] args) {
int[] A ={1,5,7,3};
int target = 10;
boolean res = new num1().hasSum(A, target);
System.out.println(res);
}
}
import java.util.Arrays;
public class num1 {
boolean hasSum(int[] A,int target){
boolean res = false;
Arrays.sort(A);
int i = 0,j = A.length-1;
while(i<j){
if(A[i] + A[j] == target){
res = true;
return res;
}else if(A[i] + A[j] < target){
i++;
}else if(A[i] + A[j] > target){
j--;
}
}
return res;
}
public static void main(String[] args) {
int[] A ={1,5,7,3};
int target = 10;
boolean res = new num1().hasSum(A, target);
System.out.println(res);
}
}