Question

Use java to find the sum of the following series (up to N terms). The program...

Use java

to find the sum of the following series (up to N terms). The program should    display the terms:

             22 + 42 + 62

For example, if N=4, then the program should display the following terms:

                          22 + 42 + 62 + 82

Sum of terms = 120   

(So How I can get 22 + 42 + 62 + 82   for the output . the answer is not only for the sum of terms =120 can you explain how you do it as well?) thank you.

Homework Answers

Answer #1
import java.util.Scanner;

public class SumNTerms {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a value for n: ");
        int n = in.nextInt();
        int total = 0;
        for (int i = 1; i <= n; i++) {
            System.out.print((2*i) + "^2");
            if (i != n) {
                System.out.print(" + ");
            }
            total += (2*i)*(2*i);
        }
        System.out.println(" = " + total);
    }
}

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
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
1- Write algorithm (in pseudo-code) for the following problem: sum of the series: 1 +2+3+…+N 2-...
1- Write algorithm (in pseudo-code) for the following problem: sum of the series: 1 +2+3+…+N 2- Convert an algorithm to a flowchart diagram. 3- Counting the primitive operations of the algorithm. 4- Determine algorithm complexity. 5- Write a complete C++ program for the previous algorithm where the program should contain the following:  Display messages.  Input any number;  Display the series.  Display the sum of the series.
How many terms of the series (-1)^n/n! do you need to add up for the partial...
How many terms of the series (-1)^n/n! do you need to add up for the partial sum to be at most 0.00001 away from the true sum of the series? What is the value of the partial sum?
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
In C Programming Language: Given an integer N, find whether the sum of the digits calculated...
In C Programming Language: Given an integer N, find whether the sum of the digits calculated repeatedly till a single digit is obtained results in the sum of 1 or not. Display 1 if the sum of the digits of N can equal 1 else display 0. Example: For 199, Sum of digits = 1+9+9=19, 1+9=10, 1+0=1 so it should display 1 For 57, sum of digits = 5+7=12, 1+2=3 so it should display 0
Write a python program to find the sum of the first n natural numbers, where the...
Write a python program to find the sum of the first n natural numbers, where the value of n is provided by the user. What is the sum of the first 200 numbers? Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: the average should always be a float. What is the average of 10.2,...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
Consider the following series. ∞ 1 n4 n = 1 (a) Use the sum of the...
Consider the following series. ∞ 1 n4 n = 1 (a) Use the sum of the first 10 terms to estimate the sum of the given series. (Round the answer to six decimal places.) s10 = 0.082036 Incorrect: Your answer is incorrect. (b) Improve this estimate using the following inequalities with n = 10. (Round your answers to six decimal places.) sn + ∞ f(x) dx n + 1 ≤ s ≤ sn + ∞ f(x) dx n ≤ s...
(a) Use any test to show that the following series is convergent. X∞ n=1 (−1)n n...
(a) Use any test to show that the following series is convergent. X∞ n=1 (−1)n n 2 + 1 5 n + 1 (b) Find the minimum number of terms of the series that we need so that the estimated sum has an |error| < 0.001.
Write a program that asks for five test scores. The program should calculate the average test...
Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision. Display: (1) your (1) interactive dialog with the console, (2) the five test scores entered, and (3) the computed average. the pseudo code is: you will need to include a library for the output formatting for specifying decimal point display: #include <iomanip> in std namespace...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT