← Back to Arrays
Question 397
Count Pairs Summing to a Target
Count Pairs Summing to a Target
The array{1, 5, 7, -1, 5}is given. Read a target integer from standard input, then count how many index pairs(i, j)withi < jsatisfyarr[i] + arr[j] == target, and print that count. For example, if the input is6, print the output shown in Expected Output. The pairs summing to6are(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 — 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.