Java Recursion Program Practise 3 - Raising base to power of index

Java Program to input two number and raising the input number to the power of the another input using Recursive Function. 

Output

import java.util.*;
class Main {
    int power(int n, int p){
        if(p==0)
        return 1;
        else {
            return (n* power(n,p-1));
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a, b;
        System.out.println("Enter the number and the power to be raised using Recursion Function");
         a = in.nextInt();
        b = in.nextInt();
        Main ob = new Main();
        System.out.println(ob.power(a,b));
        
    }
}

Comments

Translate

Popular posts from this blog

Letter to SBI Bank Manager of Local Branch to reduce the interest rate on home loan

Abhisara - the Tryst Notes

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Java Recursion Program Practise 2 - Fibonacci Series

Java Recursion Program Practise 1 - Factorial

Java Recursion Program Practise 4 - to input a number and display sum from 1 to that number

Java String Manipulation 28th Jan Practice 2 - input a string and check whether it is a palindrome or not

Imagine a situation where you get an opportunity to change one thing in your school. What would it be? Why do you want to change it? How would you bring about the change?