public class AssignmentChapter8
{
public static void main(String[] args)
{
int randomNumbers[] = new int[100];
int oddCount;
int evenCount;
for(int x = 0; x < randomNumbers.length; x++)
randomNumbers[x] = (int)(Math.random() * 25);
for(int y = 0; y < randomNumbers.length; y++)
if(randomNumbers[y] % 2 > 0)
oddCount += 1;
else
evenCount+=1;
int oddNumbers[] = getOddNumbers(oddCount, randomNumbers[]);
int evenNumbers[] = getEvenNumbers(evenCount, randomNumbers[]);
System.out.println();
System.out.println("The list of odd numbers is:");
System.out.println();
for(int a = 0; a < oddNumbers.length; a++)
System.out.print(oddNumbers[a] + "\t");
System.out.println();
System.out.println("The list of even numbers is:");
System.out.println();
for(int b = 0; b < evenNumbers.length; b++)
System.out.print(evenNumbers[b] + "\t");
}
public static int[] getOddNumbers(int oddCount, int randomNumbers[])
{
int oddNumbers[] = new int[oddCount];
int counter = 0;
for(int x = 0; x < randomNumbers.length; x++)
if(randomNumbers[x] % 2 > 0)
{
oddNumbers[counter] = randomNumbers[x];
counter++;
}
return oddNumbers;
}
public static int[] getEvenNumbers(int evenCount, int randomNumbers[])
{
int evenNumbers[] = new int[evenCount];
int counter = 0;
for(int x = 0; x < evenNumbers.length; x++)
if(randomNumbers[x] % 2 < 1)
{
oddNumbers[counter] = randomNumbers[x];
counter++;
}
return evenNumbers;
}
}
私はJavaが初めてで、100個の数字を生成し、奇数と偶数を並べ替えるプログラムを作成しようとしています。私が何をしても、プログラムは .class 予想されるエラーを出します。どんな助けでも大歓迎です。