我的計劃存在一些問題,我要求用戶輸入開始人口,每日增長百分比,以及他們將會繁殖多少天。然後計算每天的結束人口數量,同時確保他們對用戶輸入數據的限制。我每天都會得到相同的結果,而且約束條件也沒有做好。隨着時間的推移人口變化
input=JOptionPane.showInputDialog("Please enter the starting number of organisms");
startPopulation=Double.parseDouble(input);
input=JOptionPane.showInputDialog("Please enter their daily population increase as a percentage");
increase=Float.parseFloat(input);
input=JOptionPane.showInputDialog("Please enter how many days they will multiply in");
daysofIncrease=Double.parseDouble(input);
for (int days=0;days<=daysofIncrease+1;days++)
{
if (startPopulation>=2 || increase >0 || daysofIncrease>=1)
{
endPopulation=(startPopulation*increase)+startPopulation;
JOptionPane.showMessageDialog(null,"This is the organisms end population: "+endPopulation+" for day: "+days);
}
else
{
input=JOptionPane.showInputDialog("Please enter the starting number of organisms");
startPopulation=Double.parseDouble(input);
input=JOptionPane.showInputDialog("Please enter their daily population increase as a percentage");
increase=Float.parseFloat(input);
input=JOptionPane.showInputDialog("Please enter how many days they will multiply in");
daysofIncrease=Double.parseDouble(input);
}
}
}
}
「請輸入** orgranisms的起始編號**」我瞥了一眼並稍微讀錯了 – Troubleshoot
@排錯該評論不符合Stack Overflow的精神。 – hexafraction
我以爲說*請輸入生物體的起始數字*。他看到你錯了。 – Troubleshoot