1, 4, 9, 16, 25
you return the array with elements
2, 3
since there were two even and three odd elements.
Here is what I have gotten. It compiles, but doesn't count the even or the odds. It just gives me zeros....
public class Numbers
{
/**
Computes the number of even and odd values in a given array
@param values an array of integer values
@return an array of length 2 whose 0 entry contains the count
of even elements and whose 1 entry contains the count of odd
values
*/
public int[] evenOdds(int[] values)
{
int[] evenOdds= new int[2];
int oddCount=0;
int evenCount=0;
for(int i=0; i<values.length; i++)
{
if(values[i]%2==1);
oddCount++;
if(values[i]%2==0);
evenCount++;
}
values[0]=evenCount;
values[1]=oddCount;
return evenOdds;
}
}
This post has been edited by macosxnerd101: 05 December 2011 - 08:19 AM
Reason for edit:: Please use code tags

New Topic/Question
Reply



MultiQuote




|