-2

Can someone please tell how can I print the result of the following class:

public static int power2(int x, int y)
    {
        if (y==0)
            return 1;
        else
            return x*power2(x,y-1);
    }

    public static void main(String[] args) {
        power2(2,2);

    }
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Gadker
  • 1
  • 1

1 Answers1

0

You can either print it directly : System.out.println(power2(2,2)); Or you can save it to a variable and print it from there like :

int result = power2(2,2);
...
print (result);
Sister Coder
  • 324
  • 1
  • 2
  • 12