Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the Maths Function definition below for a mathematical function a(n) you are required to write two Java methods both methods will be in

Given the Maths Function definition below for a mathematical function a(n) you are required to write two Java methods – both methods will be in the same class.

a(n) = |a (1) | a(n) = = 2, 4a (n-1) -3n, n = 1 n >= 2 

An iterative method which calculates a(n) for any positive value of n. In this method you must use either a for or a while loop. You should call this method q1Iterative and it should have a definition as follows: public static int q1Iterative(int n)

A recursive method which calculates a(n) for any positive value of n. You should call this method q1Recursive. The definition of the method should be declared as follows: public static int q1Recursive(int n)

Both Java methods should only return the single value of a(n). They should not print any other values.

Input

    n, an integer value.

Sample Input 1

    1

Output

The method will print the value of a(n) for each method (which is a(1) in this case) on the same line separated by a space

Sample Output 1

    2 2

Sample Input 2

    5

Output

The method will print the value of a(n) for each method (which is a(5) in this case) on the same line seperated by a space

Sample Output 2

    -79 -79

a(n) = |a (1) | a(n) = 2, = 4a (n-1)-3n, n = 1 n >= 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here are the Java methods implementing th... 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

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Name the 5 clustering algorithms? and what they mean

Answered: 1 week ago

Question

What was the main focus of the GASB's work in 2009?

Answered: 1 week ago