using arrays or Arraylist in java language Write the method named nOdds(). * * Given an ArrayList of positive Integers, return a new list * of length "count" containing the first odd numbers from * the original list. The original will contain at least * "count" odd numbers. * * Examples: * nOdds([3, 2, 4, 5, 8], 2) returns [3, 5] * nOdds([3, 2, 4, 5, 8, 9], 3) returns [3, 5, 9] * nOdds([3, 1, 2, 4, 5, 8], 3) returns [3, 1, 5] * * @param list the ArrayList of Integers to search. * @param count the number of odd numbers to copy. * @return the first "count" odd numbers from the list. */ // TODO - Write the nOdds method here. // A utility method for testing @SuppressWarnings("unchecked") public static ArrayList al(T...o) { ArrayList result = new ArrayList(); for (T s : o) result.add(s); return result; }
using arrays or Arraylist in java language
Write the method named nOdds().
*
* Given an ArrayList of positive Integers, return a new list
* of length "count" containing the first odd numbers from
* the original list. The original will contain at least
* "count" odd numbers.
*
* Examples:
* nOdds([3, 2, 4, 5, 8], 2) returns [3, 5]
* nOdds([3, 2, 4, 5, 8, 9], 3) returns [3, 5, 9]
* nOdds([3, 1, 2, 4, 5, 8], 3) returns [3, 1, 5]
*
* @param list the ArrayList of Integers to search.
* @param count the number of odd numbers to copy.
* @return the first "count" odd numbers from the list.
*/
// TODO - Write the nOdds method here.
// A utility method for testing
@SuppressWarnings("unchecked")
public static <T> ArrayList<T> al(T...o)
{
ArrayList<T> result = new ArrayList<T>();
for (T s : o) result.add(s);
return result;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images