0
void searchForPopulationChange()
{
int input;
int searchCount = 0;
System.out.println ("Enter the Number for Population Change to be found: ");
input = scan.nextInt();
boolean found = false;
for (searchCount = 0; searchCount < populationChange.length; searchCount++)
{
if (populationChange[searchCount] == input)
{
found = true;
break;
}
}
if (found)
{
System.out.print(""+countyNames[searchCount]+" County/City with a population of "+populationChange[searchCount]+" individuals\n");
}
else
{
System.out.print("WRONG INPUT");
}
}
你好,上述目前我的節目。 我有一個問題,就是讓它拉出所有相應的變量。 IE:我輸入「200」,數組中有(2)個單位具有相應的(200)值,但是,這隻打印出其中的1個單位。
任何人有任何快速指針?
這樣做會讓我將else語句移回for循環 ,然後我的輸出顯示2 (找到)變量,但是,然後還包括一個巨大的垃圾郵件的「錯誤的輸入」錯誤輸入「 – user2517185
即時通訊不知道如何重新發布我的代碼 - ;;; – user2517185
@ user2517185我編輯了我的答案。如果你需要重新發布代碼,你仍然可以檢查'found'的值' –