Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzairmemon1 authored Oct 7, 2022
1 parent 41bfff4 commit d8a63fe
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Java/XPowerN.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;
public class XPowerN {
public static int calculate(int x , int n)
{
if(n==0) {
return 1;
}
if (x==0) {
return 0;
}
int xpower = x * calculate(x, n-1);
return xpower;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the base");
int x = sc.nextInt();
System.out.println("Enter the power");
int n = sc.nextInt();
int ans = calculate(x,n);
System.out.println( x+ " to "+ "Power " + n + " is " + ans);
}
}

0 comments on commit d8a63fe

Please sign in to comment.