-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
당신이보고있는 문제, 즉 당신이 얻고있는 결과를 기대했던 결과와 비교하여 설명 할 수 있다면, 훨씬 쉬울 것입니다. 우리가 당신을 도울 수 있도록 – Tim
'evenoddCount'를 초기화하지 않습니다 :'evenoddCount = new int [2];'. – AntonH