Java Reference
In-Depth Information
20. Consider the following method heading:
public static void tryMe( int [] x, int size);
and the declarations:
int [] list = new int [100];
int [] score = new int [50];
double [] gpa = new double [50];
Which of the following method calls is valid?
tryMe(list, 100);
a.
tryMe(list, 75);
b.
tryMe(score, 100);
c.
tryMe(score, 49);
d.
tryMe(gpa, 50);
e.
Suppose that you have the following method definition:
public static int sum( int x, int y)
{
21.
return
x + y;
}
Consider the following declarations:
int [] list1 = new int [10];
int [] list2 = new int [10];
int [] list3 = new int [10];
int a, b, c;
Which of the following method calls is valid?
a. c ¼ sum(a, b);
b. a ¼ sum(list1[0], list2[0]);
c. c ¼ sum(list1, list2);
d. for ( int i = 1; i <= 10; i++)
list3[i] = sum(list1[i], list2[i]);
22. What is the output of the following Java code?
double [] salary = {25000, 36500, 85000, 62500, 97000};
double raise = 0.03;
for ( int i = 0; i < 5; i++)
System.out.printf("%d %.2f %.2f %n", (i + 1), salary[i],
(salary[i] * raise));
23. A car dealership employs 10 salespeople. Each salesperson keeps track of the
number of cars sold each month and reports it to the management at the
end of the month. The management keeps the data in a file and assigns a
number, 1 to 10, to each salesperson. The following statement declares an
Search WWH ::




Custom Search