Write a Java application that involves the following functio
Solution
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;
import java.util.Scanner;
public class Power {
int power1(int n,int pow)
{
int res = 1;
for(int i=1;i<=pow;i++)
res = res*n;
return res;
}
int power2(int n,int pow)
{
if(pow==0)
return 1;
if(pow==1)
return n;
return n*power2(n,pow-1);
}
public static void main(String[] args)
{
Power p = new Power();
int n,pow;
Scanner input = new Scanner(System.in);
System.out.println(\"Input the value of n : \");
n = input.nextInt();
System.out.println(\"Input the value of pow : \");
pow = input.nextInt();
System.out.println(\"Result of iterative function is : \" + p.power1(n, pow));
System.out.println(\"Result of recursive function is : \" + p.power2(n, pow));
}
}
