write a java code.
Write a program using loops to compute the sum of the 30 terms of the series below.
91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 + 11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . .
Output:
Term Ratio Sum
1 13 13
2 18.4 31.4
etc etc
public class TermSum { public static void main(String[] args) { double term, sum = 0, num = 91; int n1 = 3, n2 = 2, n3 = 2, sign1, sign2; System.out.println("Term Ratio Sum"); for (int i = 1; i <= 30; i++) { if (i % 2 == 0) { sign1 = -1; } else { sign1 = 1; } if (i % 3 == 0) { sign2 = -1; } else { sign2 = 1; } term = num / (n1 + sign1*n2 + sign2*n3); sum += term; n1++; n2 += 2; n3 += 3; num++; System.out.println(i + "\t" + term + "\t" + sum); } } }
Get Answers For Free
Most questions answered within 1 hours.