Assessment 4_2_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 two dimensional list of integers of at least size two from the user, and finds the minimum and next minimum integer in this two dimensional list.

We will guarantee all numbers in the list are unique. Return the two numbers as an array; for example, if the user enters [[2,3][1,4]] you would return [1,2].

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

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

  public static void main(String[] args){

    int [][] arr1 = {{1, 2}};
    int [] result1 = {1, 2};
    System.out.println("test1: " + Arrays.equals(min(arr1), result1));
    int [][] arr2 = {{3, 1, 2}};
    int [] result2 = {1, 2};
    System.out.println("test2: " + Arrays.equals(min(arr2), result2));
    int [][] arr3 = {{3,1,2},{4,5,0,7}};
    int [] result3 = {0, 1};
    System.out.println("test2: " + Arrays.equals(min(arr3), result3));
    int [][] arr4 = {{3,1,2}, {4,5,0,7}, {-1}};
    int [] result4 = {-1, 0};
    System.out.println("test4: " + Arrays.equals(min(arr4), result4));
  }

}