advictoriam

Untitled

Jan 23rd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. public class Numbers
  2. {
  3.    /**
  4.       Computes the number of even and odd values in a given array
  5.       @param values an array of integer values
  6.       @return an array of length 2 whose 0 entry contains the count
  7.       of even elements and whose 1 entry contains the count of odd
  8.       values
  9.    */
  10.    public int[] evenOdds(int[] values)
  11.    {
  12.       int[] evenOdd = new int[2];
  13.       for(int a : values){evenOdd[(a%2 == 0) ? 0 : 1] += 1;}
  14.       return evenOdd;
  15.    }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment