chillurbrain

Task1/2_6_2

Dec 18th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Task {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int n = sc.nextInt(), m = sc.nextInt();
  7.         if (m > 0)
  8.             System.out.println(power(n,m));
  9.         else System.out.println((double)1 / power(n,-m));
  10.     }
  11.     public static int power(int x, int y) {
  12.         if (y == 0)
  13.             return 1;
  14.         else
  15.             return x * power(x, y-1);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment