From 9b74aae2c422318196d8f165629002ffe7f14e88 Mon Sep 17 00:00:00 2001 From: Tusharr0305 <113424554+Tusharr0305@users.noreply.github.com> Date: Sat, 29 Oct 2022 00:05:33 +0530 Subject: [PATCH] Create countsum.java compleated all steps given in readme file --- countsum.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 countsum.java diff --git a/countsum.java b/countsum.java new file mode 100644 index 0000000..17c4d9b --- /dev/null +++ b/countsum.java @@ -0,0 +1,22 @@ +public class find { + public static void main(String args[]) + { + int[] arr = { 1, 5, 7, -1, 5 }; + int sum = 6; + getPairsCount(arr, sum); + } + public static void getPairsCount(int[] arr, int sum) + { + + int count = 0; // Initialize result + + // Consider all possible pairs and check their sums + for (int i = 0; i < arr.length; i++) + for (int j = i + 1; j < arr.length; j++) + if ((arr[i] + arr[j]) == sum) + count++; + + System.out.printf("Count of pairs is %d", count); + } +} +