Assessment 4_3_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 grid as two dimensional list of integers. For each item in the grid, check if the number directly beneath it on the next row, when summed with the item, sums to 10; if so, your code should return true
and false
otherwise.
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_3_Sample{
public static boolean checkSum(int[][] arr){
return false;
}
public static void main(String[] args){
int [][] arr1 = {{1, 2}};
System.out.println("test1: " + (checkSum(arr1) == false));
int [][] arr2 = {{5}, {5}};
System.out.println("test2: " + (checkSum(arr2) == true));
int [][] arr3 = {{1,2,3}, {1,2,3}, {1,2,7}};
System.out.println("test3: " + (checkSum(arr3) == true));
int [][] arr4 = {{1,2,3}, {1,2,3}, {1,2,3}, {9,1,1}};
System.out.println("test4: " + (checkSum(arr4) == true));
int [][] arr5 = {{1,2,3}, {1,2,3}, {1,2,3}, {7,1,1}};
System.out.println("test5: " + (checkSum(arr5) == false));
}
}