Java program to find all pairs of elements in an integer array
Java program to find all pairs of elements in an integer array whose sum is equal to a given number.
/* *@ CopyRight : 2016 *@ Author : RAJEEVKUMAR *@ Date : 16-Mar-2018 *@ File Name : PairOfArray.java *@ Package : codding.time * */ package codding.time; public class PairOfArray { public static void main(String args[]) { int a[] = { 4, 5, 6, 7, 2, 3, 4, 5, 6, 7 }; int sum = 10; for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if (a[i] + a[j] == sum) { System.out.println(a[i] + " " + a[j] + " = " + sum); } } } } }
post a comment