-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementPairSum.java
More file actions
32 lines (23 loc) · 910 Bytes
/
ElementPairSum.java
File metadata and controls
32 lines (23 loc) · 910 Bytes
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
package arrays;
public class ElementPairSum {
static void findThePairs(int inputArray[], int inputNumber)
{
System.out.println("Pairs of elements whose sum is "+inputNumber+" are : ");
for (int i = 0; i < inputArray.length; i++)
{
for (int j = i+1; j < inputArray.length; j++)
{
if(inputArray[i]+inputArray[j] == inputNumber)
{
System.out.println(inputArray[i]+" + "+inputArray[j]+" = "+inputNumber);
}
}
}
}
public static void main(String[] args) {
findThePairs(new int[] {4, 6, 5, -10, 8, 5, 20}, 10);
findThePairs(new int[] {4, -5, 9, 11, 25, 13, 12, 8}, 20);
findThePairs(new int[] {12, 13, 40, 15, 8, 10, -15}, 25);
findThePairs(new int[] {12, 23, 125, 41, -75, 38, 27, 11}, 50);
}
}