Write a method called power the computes xn where x and n and positive integers. The method has two integer parameters and returns a value of type long.
What will be an ideal response?
```
/** x and n are nonnegative integers */
public long power(int x, int n)
{
long result = 1;
/** check for positive numbers */
if((x >= 0) && (n >= 0))
{
/** raise x to the nth power */
for(int i = n; i > 0; i--)
result *= x;
}
else
{
result = 0;
System.out.println("Fatal error.......positive integers required!");
}
return result;
}
```
You might also like to view...
In the scenario in the book, the functional roles are responsible for the implementation of policy.
Answer the following statement true (T) or false (F)
What is a probing question? What is the purpose of using a probing question in interviews?
What will be an ideal response?
In a network with no DHCP server, computers can automatically assign themselves an IP address from the reserved range of 169.254.0.1 to 169.254.255.254, an addressing mode called which of the following?
A. DHCP-Auto B. Static C. Manual D. APIPA
The header of a two-page letter includes the ____.
A. recipient's full name, Page 2, and the date B. recipient's full name, the date, and Page 2 C. the sender's full name, Page 2, and the date D. the sender's full name, the date, and Page 2