Question: 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

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 Programming Questions!