I have to write a program that computes a close enough value for the half-life of carbon-14 using comparison of floating point numbers. The while loop should be controlled by a comparison of half of the initial amount and the computed amount remaining. I'm confused as to how to get the number of years because my while loop becomes infinite and I dont know how to stop it. The value should be around 5000 years. Thanks for any help, I really appreciate it!
public class Lab321 { public static void main(String[] args) { final double EPSILON = 1.0E-7; final double DECAY = 1.14E-4; double initialAmount = 2.0E-5; double computedAmount = initialAmount - (DECAY / 100) * initialAmount; int year = 0; while (Math.abs(computedAmount - 1.0E-5) > EPSILON) { year++; double amountRemaining = initialAmount - (DECAY / 100) * initialAmount; System.out.println(amountRemaining); } System.out.println("The approximate value for the half life of carbon-14 is " + year + " years."); } }