-5
import java.util.Scanner;
import java.util.Arrays;
/**
This class prints the numeric value of a letter grade given by the user.
*/
public class Numbers
{
int countEven=0;
int countOdd=0;
private int[] digits;
private int[] evenoddCount;
Scanner input = new Scanner(System.in);
/**
Constructs numbers set to 0
@param anEfficiency the fuel efficiency of the car
*/
public Numbers()
{
digits = new int[10];
}
/**
collects 10 numbers from user and places then into array
@return the gradeValue
*/
public void inputArray(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
{
digits = {a, b, c, d, e, f, g, h, i, j};
}
/**
counts even and odds
@return numeric grade
*/
public void evenOdds()
{
for(int i=0; i < digits.length; i++)
{
if(digits[i]%2 == 0)
countEven++;
else
countOdd++;
evenoddCount = {countEven, countOdd};
}
}
/**
prints out the array of 10 positive integers
@return numeric grade
*/
public void printArray()
{
System.out.println(Arrays.toString(evenoddCount));
}
}
}
代码应该使用数组查找偶数。尽管出于某种原因,评论已经搞乱了。我似乎在第31行附近搞砸了,由于某种原因,这个程序的其余部分几乎搞砸了?我想我搞砸了我的声明。偶/奇程序无法正常工作?
现在告诉我们为什么你认为它不能正常工作 – Baby 2014-12-05 03:43:45
如果你能描述你所看到的问题 - 也就是说,与你预期的结果相比,你得到了什么结果 - 这将使它更容易为我们提供帮助。 – Tim 2014-12-05 03:43:59
你永远不会初始化'evenoddCount',因为一件事:'evenoddCount = new int [2];'。 – AntonH 2014-12-05 03:44:40