Count Pairs Summing to a Target
mediumQuestion 397The array {1, 5, 7, -1, 5} is given. Read a target integer from standard input, then count how many index pairs (i, j) with i < j satisfy arr[i] + arr[j] == target, and print that count.
For example, if the input is 6, print the output shown in Expected Output.
The pairs summing to 6 are (1,5), (1,5), and (7,-1). Each unordered pair of positions is counted once.
Expected output
3= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.