因此,以下是該程序的簡介:「根據CNNMoney.com,Facebook在2012年10月達到了10億用戶。使用您在圖4.6中學到的複合增長技術並假設其用戶基地以每月4%的速度增長,需要多少個月才能將其用戶羣增加到15億用戶?Facebook需要多少個月才能將其用戶羣擴大到20億用戶?「使用複合增長的Java程序
我有程序「工作」,但我覺得好像它不是正確計算值。我也不知道我是否正在使用最新或有效的Java技術。我絕對是一個初學者,所以任何建議或指針將非常感激。這是我到目前爲止!
package programmingassignment4.pkg32;
public class ProgrammingAssignment432 {
public static void main(String[] args) {
int user= 1000000000;
int user2= 1000000000;
double total1 = 0;
double total2 = 0;
int grandtotal1=0;
int grandtotal2=0;
int i = 1;
int j=1;
for(i=1; user<=1500000000; i++)
{
total1 = user*(.04);
user+=total1;
}
System.out.print("The total number of months to reach 1.5 billion users will be : " + i + "\n");
for(j=1;user2<=2000000000;j++)
{
total2 = user2*(.04);
user2+=total2;
}
System.out.print("The total number of months to reach 2 billion users will be : " + j);
}
}
如果您想更詳細地查看您的代碼,codereview.stackexchange.com可能更符合您的需求。 – Others 2015-04-04 20:42:47
在發佈到[codereview.se]之前,提問者應該首先弄清楚這是什麼編程語言(無語言標籤),然後是否他們確定它能產生正確的結果並按預期工作。 – nhgrif 2015-04-04 20:45:15
請詢問更具體的問題。我不覺得價值觀是正確的。我知道或不知道。你做? – 2015-04-04 20:45:39