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)
- Write a recursive method that returns thelargest integer in an array. Write a test program that prompts the user to enter alist of eight integers and displays the largest element.arrow_forwardJava, Rewrite the following iterative method as a recursive method that computes the same thing. Note:  your recursive method will require an extra parameter.public int iterative1(int x){int count = 0, factor = 2;while (factor < x){if (x % factor == 0) count++;factor++;}return count;}arrow_forwardJAVA Question 2: For two integers m and n, their GCD (Greatest Common Divisor) can be computed by a recursive method. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Method body: If m is 0, the method returns n. If n is 0, the method returns m. If neither is 0, the method can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n (or m % n). The recursive method cannot have loops. Note: although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. main method: Prompt and read in two numbers to find the greatest common divisor. Call the gcd method with the two numbers as its argument. Print the result to the monitor.  Example program run: Enter m: 12 Enter n: 28 GCD(12,28) = 4 And here is what I have so far, package CSCI1302;import java.util.*;public class RecursionDemo {   public static void…arrow_forward
- Write a recursive method named printLevel (Node<T> reeRef, int level) (with an assumption that it will be written inside class BST) that prints the nodes in a certain level. The method should take two parameters: the root and the level number that you should print the nodes at. Write a test drive main program which tests this method.    USE JAVA LANGUAGE PLEASarrow_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_forwardrecursive 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_forward
- 1. Let product(n,m) be a recursive method that computes the product of two positive integers, using only addition and subtraction. To make this method a recursive one, you are to make a) a base case when m = 1, b) a general case when m ≠1. For a general case, the return value should be n plus the result of a recursive call to the method product() with parameters n and m - 1. Write a short Java code for this method, along with a test program.arrow_forwardRewrite the private static int recurseMax method without using Java API public class Recursion{  public static void main(String[] args){     // My tests (DO NOT MODIFY!)     int[] a = {3,2,6,4,15,7,9,8,6};     p(recurseSum(a));           // Sum should be 60     p(recurseMax(a));           // Max should be 15     // End of tests!  }    // Recursive methods below here...  public static int recurseSum(int[] a){     // TODO: This is the wrapper method. You must complete this AND implement helper method     int total = recurseSum(a, a.length);     return total;  }  private static int recurseSum(int[] a, int i){     if (i <= 0)          return 0;      return (recurseSum(a, i - 1) + a[i - 1]);  }    public static int recurseMax(int[] a){         int max = recurseMax(a, a.length);     return max;  }  private static int recurseMax(int[] a, int i){     if(i == 1)        return a[0];     return Math.max(a[i-1], recurseMax(a, i-1));  }  //…arrow_forward• Write a recursive method to complete the class BaseRaiseToN. • The method: public static int raiseBToN(int base, int exp) computes and returns the value of Bn using recursion.• What value/values of n will stop the recursion (base case)?• A precondition of this method is that B be a positive number greater than zero Sample Output Enter the base4Enter the exponent 3 4 to 3 is 64arrow_forward
- In Java Ackermann’s Function Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a method ackermann(m, n), which solves Ackermann’s function. Use the following logic in your method: If m = 0 then return n + 1 If n = 0 then return ackermann(m - 1, 1) Otherwise, return ackermann(m - 1, ackermann(m, n - 1)) Test your method in a program that displays the return values of the following method calls: ackermann(0, 0) ackermann(0, 1) ackermann(1, 1) ackermann(1, 2)ackermann(1, 3) ackermann(2, 2) ackermann(3, 2)arrow_forwardjava Write a recursive method largestDigitthat accepts an integer parameter and returns the largest digit value that appears in that integer. Your method should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. The following table shows several example calls: Call Value Returned largestDigit(14263203) 6 largestDigit(845) 8 largestDigit(52649) 9 largestDigit(3) 3 largestDigit(0) 0 largestDigit(-573026) 7 largestDigit(-2) 2 Obey the following restrictions in your solution: You may not use a String, Scanner, array, or any data structure (list, stack, map, etc.). Your method must be recursive and not use any loops (for, while, etc.). Your solution should run in no worse than O(N) time, where N is the number of digits in the number.arrow_forwardThe nth harmonic number is defined non-recursively as: H(n)=1+1/2+1/3+1/4+...+1/n Come up with a recursive definition and use it to guide you to write a method definition for a double-valued method named “harmonic” that accepts an int parameter n and recursively calculates and returns the nth harmonic number. Write a test program that displays the harmonic numbers, H(n)=1,2,3,4...10arrow_forward
- 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