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