Write a recursive method to compute the power of x n for non-negative n.
What will be an ideal response?
```
public static int power(int x, int n)
{
if(n < 0)
{
System.out.println("Illegal argument to power");
System.exit(0);
}
if(n > 0)
return (power(x, n-1) * x);
else
return(1); //base case
}
```
You might also like to view...
Which of the following is an example of a denial-of-service attack?
A. Clicking a link in an e-mail that happens to contain malware B. Installing a keylogger on a system in an attempt to collect usernames and passwords C. Flooding a system with ping requests in an attempt to take it down D. View medical records to satisfy one's curiosity
The Linux basename utility has an optional second argument. If you give the command basename path suffix, basename removes the suffix and the prefix from path:
$ basename src/shellfiles/prog.bash .bash prog $ basename src/shellfiles/prog.bash .c prog.bash