Question

write a java code. Write a program using loops to compute the sum of the 30...

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

Homework Answers

Answer #1
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);
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using for loops: - write a Java program that adds numbers between 1 to 100 and...
Using for loops: - write a Java program that adds numbers between 1 to 100 and prints the result. - write a Java program that adds odd numbers between 1 to 100 and prints the result - write a Java program that averages even numbers between 5 to 30 and prints the result
program in java 1- Write a code to remove continuous repeatitive elements of a Linked List....
program in java 1- Write a code to remove continuous repeatitive elements of a Linked List. Example: Given: -10 -> 3 -> 3 -> 3 -> 5 -> 6 -> 6 -> 3 -> 2 -> 2 -> NULL The answer: -10 -> 3 -> 5 -> 6 -> 3 -> 2 -> NULL
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
11. Write a program to compute the sum of the series 12 + 22 + 32....
11. Write a program to compute the sum of the series 12 + 22 + 32. . . ., such that the sum is doesnot exceed 1000. The program should display how many terms are used in the sum. {3 marks} matlab only 1 to power of 2 , 2 to the power of 2 , 3 to the power of 3 , not 12 + 22 + 32
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
Write a Python program using while loop that finds and prints the sum of this geometric...
Write a Python program using while loop that finds and prints the sum of this geometric series. 1 + 2 +4 +8 + … + 1024
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display...
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display 5 lines of smiley faces. The following would be the output of your program: Note: Sample program is in the "Important Documents", Module 6 folder) Hello:                          Bye!
The following table contains recorded values on a level transmitter of a tank that’s holding water....
The following table contains recorded values on a level transmitter of a tank that’s holding water. The samples are taken every hour for 24 hours. Hours 1 2 3 4 5 6 7 8 9 10 11 12 Litres 100 101 104 106 99 50 103 91 110 91 93 92 Hours 13 14 15 16 17 18 19 20 21 22 23 24 Litres 95 96 91 92 101 104 106 125 106 101 104 100 Calculate the following...
Write a MASM program that computes the sum of the integers from 1 to N where...
Write a MASM program that computes the sum of the integers from 1 to N where N is a positive integer. Use the equal sign directive to define N. Save the sum in the EAX register. You must use loops. For example, 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 Language ( Assembly)...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades and add a linear trendline. What is the​ model? If a student scores 7878 on the​ midterm, what would you predict her grade on the final exam to​ be? Student Midterm Final Exam 1 75 64 2 85 91 3 80 68 4 88 83 5 76 60 6 67 80 7 78 74 8 95 94 9 67 61 10 93 87 11...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT