Assessment 3_6_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 the user enters a list of integers. Return a new list where you add together every odd integer in the list, and return this sum. For example, if the user enters [1, 1, 3, 4, 5]
, you would return 10
.
Code Template and Test cases
public class Assess3_6_Sample{
public static int addOdd(int[] original){
return -9999999;
}
public static void main(String[] args){
int [] arr1 = {};
System.out.println("test1: " + (addOdd(arr1) == 0));
int [] arr2 = {1};
System.out.println("test2: " + (addOdd(arr2) == 1));
int [] arr3 = {1, 3};
System.out.println("test3: " + (addOdd(arr3) == 4));
int [] arr4 = {2, 1, 3, 4};
System.out.println("test4: " + (addOdd(arr4) == 4));
int [] arr5 = {2,1,3,4,5};
System.out.println("test5: " + (addOdd(arr5) == 9));
int [] arr6 = {2,1,3,4,5,1};
System.out.println("test6: " + (addOdd(arr6) == 10));
}
}