Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int pow(int a, int b)
- {
- int x = 1;
- if(b==0)
- {
- return 1;
- }
- else if(b%2!=0)
- {
- return a * pow(a,b-1);
- }
- else
- {
- x = pow(a,b/2);
- return x*x;
- }
- }
- public static void main(String[] args) {
- Scanner liczba = new Scanner(System.in);
- System.out.print("Podaj liczbe: ");
- int a = liczba.nextInt();
- System.out.print("Podaj liczbe: ");
- int b = liczba.nextInt();
- System.out.print(pow(a,b));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement