Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA Programming help please! Write a static method named sumoddns that prints terms of the following mathematical sequence: sum = firstOdd +...+5+3+1+++ +* +1/lastOdd Your
JAVA Programming help please!
Write a static method named sumoddns that prints terms of the following mathematical sequence: sum = firstOdd +...+5+3+1+++ +* +1/lastOdd Your method should accept two integers as parameters representing a start number and an end number, and should add and print odd terms of the sequence from start down to 1 and 1/3 up to end. For example, if your method is passed 8 and 14, print terms as shown in the example below. You should round your sum to 3 digits past the decimal point. Hint: You will need two loops; one for whole numbers and one for fractional numbers. I suggest writing the first loop to count from start down to 1 and copy and paste it, changing it to count from 1/3 up to end. You must handle the fencepost problem but do not know if the first integer in the array will be printed. You can add a Boolean to record the first odd printed and an if-else in the loop to print as shown below. The following is the output from the call sumoddns (8, 14); 7 +5+3 +1 +1/3 + 1/5 + 1/7 + 1/9+ 1/11 + 1/13 = 16.955 If your method is passed a value less than 0 for either parameter, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls: Calls sumOddns (-1, 10); sumOddNS (3, 3); sumOddns (7,0); Output 3 + 1 + 1/3 = 4.333 7 + 5 + 3 + 1 = 16.000 Call sumOddNs (9, 9); Output 9 + 7 + 5 + 3 + 1 + 1/3 + 1/5 + 1/7 + 1/9 = 25.787 Hint: You will need two loopsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started