in a file problem1.java implement a static method with the signature: public static int pow(int x, int n); your method should recursively calculate the value of x^n (x raised to the n power). you may assume that x and n are both positive integers and you do not have to error check the parameters. hint: set up a simple recursion similar to how we setup the factorial recursion in class. write a main method within problem1.java that tests the method out on a few different values of x and n.

Respuesta :

Using the knowledge in computational language in JAVA it is possible to write a code that function for the following statements: Java do-while Use Java do-while loop format.

Writting the code:

import java.util.*;

public class Main

{

   //recuresive function for calculate x^n

   public static int pow(int x,int n){

       if(n==0)

           return 1;

       else

           return x*pow(x,n-1);

   }

   

public static void main(String[] args) {

             //scanner for taking input

 Scanner sc=new Scanner(System.in);

             //infinite loop stop when user enter Y in last

 while(true){

 System.out.print("Enter x: ");

 int x=sc.nextInt();

 System.out.print("Enter n : ");

 int n=sc.nextInt();

 System.out.printf("pow(%d,%d) :%d",x,n,pow(x,n));

 char c;

 System.out.print("\nYou Want to Continue(Y/N): ");

 c=sc.next().charAt(0);

 if(c=='Y'){

     break;

 }

 }

}

}

See more about JAVA at brainly.com/question/18502436

#SPJ1

Ver imagen lhmarianateixeira