Question #289770

In a science research lab, the combination of two nuclear chemicals produces initial energy as X. This energy X changes at a consistent rate R every second. The scientist wishes to calculate the total energy produced if the reaction is allowed to occur for N seconds.



Write an algorithm to find the total



energy produced.

Expert's answer

public class Main {
    public static void main(String[] args) {
        int x = 10;
        int r = 2;
        int n = 5;
        int total = x;
        for (int i = 0; i < n; i++) {
            total += (x + r);
            x += r;
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS