Java Reference
In-Depth Information
16. Consider the following method:
public static int secret( int one)
{
int i;
int prod = 1;
for (i = 1; i <= 3; i++)
prod = prod * one;
return prod;
}
a. What is the output of the following Java statements?
i. System.out.println(secret(5));
ii. System.out.println(2 * secret(6));
b. What does the method secret do?
17. Can a void method have a return statement? If your answer is yes, in what
form?
18. Write appropriate method headings for the following methods:
a. Calculate and return the sum of two decimal numbers.
b. Compute and return the average speed of a car, given the distance
traveled (as in int ) and traveling time (in hours and minutes of type
int ).
c. Given the radius of a circle, output the area of the circle.
d. Given a student's name and three test scores (of type int ), output the
student's name and average test score.
e. Given a number, return true if the number is a prime; otherwise,
return false .
f. Given the cost of an item and the sales tax (as a decimal number), return
the total sale price.
g. Given a decimal number, output the square root if the number is
nonnegative; otherwise, output an appropriate error message.
19. What is the output of the following program?
public class Chapter7Ex19
{
7
public static void main(String[] args)
{
System.out.println(mystery(7, 8, 3));
System.out.println(mystery(10, 5, 30));
System.out.println(mystery(9, 12, 11));
System.out.println(mystery(5, 5, 8));
System.out.println(mystery(10, 10, 10));
}
Search WWH ::




Custom Search