This is extremely simple and I'm sorry I am having trouble getting this to work. It works when I remove the while loop with just the processing, but I'm not sure what I'm doing wrong with the whileloop. Any suggestions?
/*Cobalt
60, a radioactive form of cobalt used in cancer therapy, decays or
dissipates over a period of time. Each year, 12 percent of the
amount present at the beginning of the year will have decayed. If
a container of cobalt 60 initially contains 10 grams, create a
Java program to determine the amount remaining after five years. */
public class Cobalt {
public static void main(String[] args) {
//dec
double CInitial = 10.0;
double decay = .12;
double CUpdatedA, CUpdatedB;
//proc
int years = 0;
while (years < 5);
{
CUpdatedA = CInitial * decay;
CUpdatedB = CInitial - CUpdatedA;
years++;
}
//out
System.out.println("the amount of cobalt left after 5 years is"
+ CUpdatedB);
}
}
;after it, meaning it does nothing.whilebody computes the same value over and over, while incrementingyear.yearis not thewhilebody, as pointed out by @Natecat.CUpdatedAandCUpdatedBwill get the same value on every iteration because they are dependent on variables that are loop invariant.