我已經成功地編譯這個java程序(這會產生0到25之間的100個隨機數字,把它們放在一個陣列,並將它們分類成基於兩種不同的陣列,每個陣列是偶數還是奇數),儘管它不運行。我懷疑我在一個while循環中犯了一個錯誤,儘管我不確定。另外,我掙扎着爬在正確格式化的問題的代碼,所以標籤是有點不同,但它仍然是大多清晰可辨。這裏是文字的.java:我需要幫助,我介紹到Java分配
public class Assignment8
{
public static void main(String [] args)
{
int storage [] = new int[100];
int j = 0;
while (storage.length < 100) {
int testVariable = 0 + (int) (Math.random() * ((25 - 0) + 1));
storage[j] = testVariable;
j++;
}
int oddArray[] = OddNumbers(storage);
int evenArray[] = EvenNumbers(storage);
int currentNumber = 0;
System.out.println("The odd numbers are: " + "\n");
while (currentNumber <= 99) {
System.out.println(oddArray[currentNumber] + "\n");
currentNumber++;
}
System.out.println("\n" + "The even numbers are: " + "\n");
currentNumber = 0;
while (currentNumber <= 99) {
System.out.println(evenArray[currentNumber] + "\n");
currentNumber++;
}
}
public static int[] OddNumbers(int storage[])
{
int currentNumber = 0;
int currentValue = storage[currentNumber];
int oddArray[] = new int[100];
while (currentNumber <= 99) {
if (storage[currentNumber] % 2 != 0) {
oddArray[currentNumber] = currentValue;
} else {
continue;
}
currentNumber++;
}
return oddArray;
}
public static int[] EvenNumbers(int storage[])
{
int currentNumber = 0;
int currentValue = storage[currentNumber];
int evenArray[] = new int[100];
while (currentNumber <= 99) {
if (storage[currentNumber] % 2 == 0) {
evenArray[currentNumber] = currentValue;
} else {
continue;
}
currentNumber++;
}
return evenArray;
}
}
的地方,開始是在你的IDE調試一次通過一行代碼步驟。你做到了嗎?如果是這樣,告訴我們你發現你不明白。 –
請包括示例輸出或錯誤。 – nateyolles
這不是重點,但爲什麼寫'25-0'而不是'25' – nhouser9