Question: JAVA Question Please Help! Write a program that will calculate the sum of the first n odd integers, and the sum of the first n

JAVA Question Please Help!

Write a program that will calculate the sum of the first n odd integers, and the sum of the first n even integers.

Use a Do while loop

Use a for loop

Use one method that takes atleast two arguments to display odd or even table

Use one method which calculates and returns the total at the end.

Here is a sample of how the program should run:

How many odd integers would you like to add? 5

Count Odd Integer Sum

1 1 1

2 3 4

3 5 9

4 7 16

5 9 25

The sum of the first 5 odd integers is 25

How many even integers would you like to add? 7

Count Even Integer Sum

1 2 2

2 4 6

3 6 12

4 8 20

5 10 30

6 12 42

7 14 56

The sum of the first 7 even integers is 56

Do you want to add again? Enter a negative number to quit. 3

How many odd integers would you like to add?

Make sure your program works with any input value from 1 to 10000.

REMEMBER! The sum of the first 5 odd integers is 1 + 3 + 5 + 7 + 9. It is NOT the sum of the odd integers up to 5!

Step1: Write a Java program, with comment statements and test it with the compiler. Make sure it works properly and gives the correct answers for different inputs.

Step 2: Take a screenshot of output for atleast 2 different inputs.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!