Assessment 4_1_sample

Instructions

This assessment is designed to be completed in 10 minutes or less.

Copy the template below and get all the test cases to pass. Hard-coding answers will not receieve credit; your solution must work for valid arrays.

The problem

Write code that takes a list of integers from the user. Count the number of unique pairs of numbers that sum to 10 in the incoming list.

We will guarantee that the incoming list is all unique integers. A number may be used more than once to form a sum, and each ordering of pairs is counted as a sum (so if the numbers 1 and 9 appear in the list, (1,9) and (9,1) are both pairs and therefore generate two pairs that add in towards the total sum of pairs (this will make your algorithm simpler to write).

Please do not use any Java code or libraries that we have not covered in class; this defeats the purpose of the assessment and will not receive credit.

Code Template and Test cases

import java.util.Arrays;

public class Assess4_1_Sample{

  public static int countPairs(int[] arr){
    return -999999;
  }

  public static void main(String[] args){

    int [] arr1 = {};
    System.out.println("test1: " + (countPairs(arr1) == 0));
    int [] arr2 = {1};
    System.out.println("test2: " + (countPairs(arr2) == 0));
    int [] arr3 = {1, 2};
    System.out.println("test3: " + (countPairs(arr3) == 0));
    int [] arr4 = {4, 6};
    System.out.println("test4: " + (countPairs(arr4) == 2));
    int [] arr5 = {1,2,3,4,6,7,8,9,10,0,-1,11,33};
    System.out.println("test5: " + (countPairs(arr5) == 12));
    int [] arr6 = {1,2,3,4,5,6,7,8,9,10,0,-1,11,33};
    System.out.println("test6: " + (countPairs(arr6) == 12));
  }

}