Question
Write a method integerPower (base, exponent) that returns the value of base exponent as an integer. For example, integerPower (3,4) calculates 3 4 or (3*3*3*3)
Write a method integerPower(base, exponent) that returns the value of baseexponentas an integer. For example, integerPower(3,4) calculates 34 or (3*3*3*3) and returns 81. Assume that exponent is a positive, nonzero integer and that base is an integer. Methos integerPower should use a forstatement to control the calculation. Do not use any math library methods.
Hint: initialize product 1, loop "exponent" times. In each iteration, multiple product by base.
2. Write a method reverse that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the method should return 1367.
3. Define a method triangle. It should take one parameter of type int. If the user enters 5, it will print out a triangle in 5 rows like
*
**
***
****
*****
4. Define a method called menu which prints a menu like
1.Integer Power
2.Reverse Integer
3.Triangle
4.Exit
5. All methods should be declared as static
6. In your main method, create a Scanner and ask the user to enter an option then enter a do/while loop. In the loop, using a switch statement.
a. If the user enters 1, ask the user enter base and exponent then call interPower method to get the result, then print out the result.
b. If the user enters 2, ask the user to enter an integer then print out the reversed number.
c. If the user enters 3, ask for an integer then print a Triangle pattern with *'s
d. Terminate the loop if the user enters option 4.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the implementation of the methods and the menu system as described import javautilScanner publ...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