$ 2500로 시작하여 7.5 %이자로 시작할 경우 $ 5000에 도달하는 데 걸리는 시간을 계산하는 것이 나의 임무입니다. 계산은 10 년이어야하지만 11 년을 출력합니다. 이것은 간단한 구문 에러 일지 모르지만 나는 지난 2 시간 동안 이것을 행운으로 고치려고 노력해 왔습니다.자바 복리 계산
final double principle = 2500.00;
double accrued = 0;
final double interest = 0.075;
int year = 0;
double interest1 = 1.0 + interest;
while (accrued < 5000.00)
{
accrued = principle * Math.pow(interest1, year);
year++;
}
System.out.printf("It would take %d years to reach at least $5000 if you start with $2,500 with 7.5%% compound interest.", year);
당신은 이런 이유를 몇 가지 단계별 디버깅을해야한다. –
계산을 수행 한 후 연도가 증가하고 계산 전에 증분을 이동하십시오. – pstrjds
@pstrjds 고칠 줄 알았다. 고마워. –