Assessment 4_8_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

Imagine that the user provides a one dimensional list. Return a one dimensional list that is the version of that original list where each item is a string representation of all pairs in the original list.

For example, if the user enters [1, 2, 3, 4], your code would return the array ["1-2", "1-3", "1-4", "2-1", "2-3", "2-4", "3-1", "3-2", "3-4", "4-1", "4-2", "4-3"].

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_8_Sample{

  public static String[] allPairs(int[] arr){
    String[] result = new String[2];
    return result;
  }

  public static void main(String[] args){

    int [] arr1 = {};
    String [] result1 = {};
    System.out.println("test1: " + Arrays.equals(allPairs(arr1), result1));
    int [] arr2 = {1};
    String [] result2 = {};
    System.out.println("test2: " + Arrays.equals(allPairs(arr2), result2));
    int [] arr3 = {1, 3};
    String [] result3 = {"1-3", "3-1"};
    System.out.println("test3: " + Arrays.equals(allPairs(arr3), result3));
    int [] arr4 = {4, 6, 1};
    String [] result4 = {"4-6", "4-1", "6-4", "6-1", "1-4", "1-6"};
    System.out.println("test4: " + Arrays.equals(allPairs(arr4), result4));
    int [] arr5 = {4, 6, 1, 2, 3};
    String [] result5 = {"4-6", "4-1", "4-2", "4-3", "6-4", "6-1", "6-2", "6-3", 
      "1-4", "1-6", "1-2", "1-3", "2-4", "2-6", "2-1", "2-3", "3-4", "3-6", "3-1", "3-2"};
    System.out.println("test5: " + Arrays.equals(allPairs(arr5), result5));
  }

}