Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING JAVA Multiplying two integers, a and b, is actually done by adding the first number, a, to itself b times. Dividing two numbers, a

USING JAVA Multiplying two integers, a and b, is actually done by adding the first number, a, to itself b times. Dividing two numbers, a and b, is likewise actually done by subtracting the first number, a, from the second number, b, repeatedly until b is smaller than a (this is the remainder). The number of subtractions done is the number of times b goes into a. Write a recursive method that will multiply two numbers by adding the first to itself this way. Write a second recursive method that will divide two numbers this way. Write two non-recursive methods using loops to do the same operations. Generate two random numbers in the loop and call your recursive and your iterative methods with those two random numbers. Partial Pseudo-code: In main Create a loop so you can call your recursive and iterative methods lots of times and get a better picture of the performance difference. Get two random positive numbers Call recursive multiply or divide with them Call iterative multiply or divide (make sure it is the same method as above) with them In multiply (recursive) if b is not 0 add a to result subtract 1 from b return multiply with new parameters else return result In divide (recursive) If b is greater than a subtract b from a, add one to result return divide with new parameters else return result

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_2

Step: 3

blur-text-image_3

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

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

Where do attitudes come from? How do they change?

Answered: 1 week ago

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago