You are here:   HomeJava ProgrammingControl Structures in JavaFind Recursion Power(x,n) Using Java Example
by Dinesh Thakur Category: Control Structures

step 1: Read n, x

step 2: Set r= 1

step 3: If value of n is 1 then print n and goto step - 8

step 4: Repeat through step-6 until j > 0

step 5: r=r*i

step 6: Update j as j=j-1

step 7: Print r

step 8: Exit

Here is the Java Example for the program RecursionPower

import java.util.Scanner;

public class RecursionPower
{
                 public static void main(String args[])
        {
                        int n, x, power;
                 Scanner s=new Scanner(System.in);
                 System.out.println("Enter values for n and x");
                 n=s.nextInt();
                 x=s.nextInt();
                 power=rec(n,x);
                 System.out.println("\npower IS :"+power);
          }
                    static int rec(int i,int j)
                 {
                         int r=1;
                          if(i==1)
                            return i;
                          else
                                                  {
                             while(j>0)
                                  {
                                       r=r*i;
                                          j--;
                                  }
                                     return r;
                           }
                   }
}

Recursion Power(x,n) Using Java Example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article