-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.java
39 lines (28 loc) · 883 Bytes
/
check.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
29
30
31
32
33
34
35
36
37
38
39
// GIVEN N ARRAY ELEMENTS , CHECK IF THERE EXISTS A PAIR(I,J) SUCH THAT ARR[I]+ARR[J]==K AND I::J {I AND J ARE INDEX VALUE}
import java.util.*;
class check{
public static void main(String args[]){
Scanner we=new Scanner(System.in);
System.out.println("enter length");
int l=we.nextInt();
int[]arr=new int[l];
System.out.println("enter elements");
for(int i=0;i<l;i++){
arr[i]=we.nextInt();
}
System.out.println("enter sum value");
int k=we.nextInt();
int flag=0;
for(int i=0;i<l-1;i++){
for(int j=i+1;j<=l-1;j++){
if(arr[i]+arr[j]==k){
System.out.println("Sum of values at position "+(i+1)+" and "+(j+1)+ " is equal to "+ k);
flag=1;
}
}
}
if(flag==0){
System.out.println("no such pair exist");
}
}
}