Explanation of Solution
Complete program:
//Import required packages
import java.util.*;
//Definition of class Compound
public class TenPower
{
//Definition of class main
public static void main(String[] args)
{
//Create an object for scanner class
Scanner sc = new Scanner(System.in);
//Get the number from the user
System.out.println("Enter a number:");
int number = sc.nextInt();
//Call the method "computeTenToThe()"
int result = computeTenToThe(number);
//Print the result
System.out.println("The result is " + result);
}
//Definition of method "powerTen"
public static int computeTenToThe(int n)
{
//Declare the variable "res"
int res;
//Check whether "n" equals to "0"
...Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- recursive solution oddEvenMatchRec:the method takes an integer array as a parameter and returns a boolean. The method returns trueif every odd index contains an odd integer AND every even index contains aneven integer(0 is even). Otherwise it returns falsarrow_forwardDo not use static variables to implement recursive methods. USING JAVA USING: // P5 public static long computePay(int day) { } You have been offered a job that pays as follows: On the first day, you are paid 1 cent, on the second day, 2 cents, on the third day, 4 cents and so on. In other words, your pay doubles every day. Write a recursive method computePay that for a given day number computes the pay in cents. Assume that you accumulate all the money that you are paid. Write a recursive method computeSavings that computes the sum that you have accumulated on a given day. Show the output of computePay and computeSavings for day number 39.arrow_forwardUsing JAVA Recursive Power Method Write a method called powCalthat uses recursion to raise a number to a power. The method should accept two arguments: The first argument is the exponentand the second argument is the number to be raised(example”powCal(10,2)means2^10). Assume that the exponent is anonnegative integer. Demonstrate the method in a program called Recursive (This means that you need to write a program that has at least two methods: mainand powCal. The powCal method is where you implement the requirements above and the main method is where you make a method call to demonstrate how your powCalmethod work).arrow_forward
- 3arrow_forwardVoid doo(int n){ If (n==0} Return 0; else doo(n-1); cout<arrow_forwardhelp create a Java recursive method that determines if a number is a prime numberarrow_forwardThe solution must be recursive sumNRec: The method takes an integer array A and returns the sum of all integers in the parameter array.arrow_forwardsolve q6 only pleasearrow_forwardPublic class Utilities { getDigits Method: public static java.lang.String getDigits(java.lang.String str) Returns a string with the digits (if any) present in the str parameter. You can assume str will never be null. You can use Character.isDigit() to determine whether a character is a digit. You may not use an auxiliary method in order to implement this method. Your implementation must be recursive and you may not use any loop construct. From the String class, the only methods you can use are length(), isEmpty(), charAt() and substring. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: str - Returns: String with digits or empty stringarrow_forwardPart (1) Write a recursion method named CalculateSeries, that will receive one integer valuen as parameter. The method will calculate and return the term n in the following series: T(0)= 0 T(n)= 2 T(n-1) +1 Part (2) Write the main method to test your method. Enter n >> 5 T(5) = 31 %3Darrow_forward1. Let product(n,m) be a recursive addition-subtraction method for multiplying two positive integers. Recursive cases for m = 1 and m < 1 make this method. The return value should be n plus a recursive product() call with n and m - 1. Test a Java method.arrow_forward15) Why is the following method one which has infinite recursion?public int infiniteRecursion(int n){if (n > 0) return infiniteRecursion(n) + 1;else return 0;}a) Because there is no base caseb) Because the base case will never be truec) Because the recursive call does not move the parameter closer to the base cased) Because the recursive call moves the problem further away from the base casee) None of the above, there is no infinite recursion in this methodarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education