Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static int pow(int a, int b)
  2. {
  3. int x = 1;
  4. if(b==0)
  5. {
  6. return 1;
  7. }
  8. else if(b%2!=0)
  9. {
  10. return a * pow(a,b-1);
  11. }
  12. else
  13. {
  14. x = pow(a,b/2);
  15. return x*x;
  16. }
  17.  
  18.  
  19. }
  20.  
  21.  
  22. public static void main(String[] args) {
  23.  
  24. Scanner liczba = new Scanner(System.in);
  25.  
  26. System.out.print("Podaj liczbe: ");
  27. int a = liczba.nextInt();
  28. System.out.print("Podaj liczbe: ");
  29. int b = liczba.nextInt();
  30.  
  31. System.out.print(pow(a,b));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement