-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
  • 90,369
  • 161
  • 124
  • 175
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);
Sis On Code
  • 180
  • 1
  • 10