What are the constraints on the argument values of these two methods, and explain what the method does.

int power( int base, int exponent)
{
if (exponent == 0)
    return 1;
else
    return (base * power(base, exponent -1));
}

int factorial (int n)
{
if (n > 0)
    return (n * factorial (n-1));
else
if (n == 0)
    return 1;
}

Recommended Answers

All 3 Replies

The tutorial discusses the range of values a primitive can hold:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Have you tried executing those methods to see what values they return?
Call the methods with different values and print out the results.
If you have any questions about the results, post the print outs that show what the args to the methods were and what the results were.

It's your homework. Do some google and you should find the exact answers... Also, this is for you to think, not for you to ask for answers. <snip>

PS: The format of the code is in C/C++. It is not Java.

nice Java exercise: explain why that code wouldn't compile in Java?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.