Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a recursive java function with the following behavior: For determining if a number is even or odd, look at the whole number portion, so

Create a recursive java function with the following behavior: For determining if a number is even or odd, look at the whole number portion, so 3.75 is odd, while 2.25 is even. If the current value is even add the current value to the total. If the current value is odd, subtract the current value from the total The next number in the sequence will be: 1.6 times the current value if the current value is even. the current value divided by 4 if the current value is odd and above 10 the current value is divided by 3 if the value is odd and 10 or below. The sequence stops if the current number in the sequence is below 1.

Your program should ask the user to enter a starting value and then print all values in the sequence as well as the ending total.

Example output:

Starting value: 4

val: 4.0000 6.4000 10.2400 16.3840 26.2144 41.9430 10.4858 16.7772 26.8435 42.9497 68.7195 109.9512 27.4878 6.8719 10.9951 17.5922 4.3980 7.0369 2.3456 3.7530 1.2510 0.4170

Result is: 44.6098

---------------------------------------------------------------

Starting value: 10

val: 10.0000 16.0000 25.6000 6.4000 10.2400 16.3840 26.2144 41.9430 10.4858 16.7772 26.8435 42.9497 68.7195 109.9512 27.4878 6.8719 10.9951 17.5922 4.3980 7.0369 2.3456 3.7530 1.2510 0.4170

Result is: 41.0098

---------------------------------------------------------------

Starting value: 3

val: 3.0000 1.0000 0.3333

Result is: -4.0000

---------------------------------------------------------------

Starting value: 100

val: 100.0000 160.0000 256.0000 409.6000 102.4000 163.8400 40.9600 65.5360 16.3840 26.2144 41.9430 10.4858 16.7772 26.8435 42.9497 68.7195 109.9512 27.4878 6.8719 10.9951 17.5922 4.3980 7.0369 2.3456 3.7530 1.2510 0.4170

Result is: 44.3538

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

Students also viewed these Databases questions

Question

1. What is the overall objective of scheduling?

Answered: 1 week ago