Java Reference
In-Depth Information
x = 10; k = secret(x);
System.out.println(x + " " + k + " "
+ another(x, k));
c.
d.
x = 5; y = 8;
System.out.println(another(y, x));
14.
Consider the following method headings:
public static int
test(
int
x,
char
ch,
double
d,
int
y)
public static double
two(
double
d1,
double
d2)
public static char
three(
int
x,
int
y,
char
ch,
double
d)
Answer the following questions:
a.
How many parameters does the method
test
have? What is the type
of the method
test
?
b.
How many parameters does method
two
have? What is the type of the
method
two
?
c.
How many parameters does method
three
have? What is the type of
the method
three
?
d.
How many actual parameters are needed to call the method
test
?
What is the type of each parameter, and in what order should you use
these parameters in a call to the method
test
?
e.
Write a Java statement that prints the value returned by the method
test
with the actual parameters
5
,
5
,
7.3
, and
'z'
.
f.
Write a Java statement that prints the value returned by method
two
with the actual parameters
17.5
and
18.3
, respectively.
g.
Write a Java statement that prints the character that comes after the one
returned by the method
three
. (Use your own actual parameters.)
15.
Consider the following method:
public static int
mystery(
int
x,
double
y,
char
ch)
{
int
u;
if
('A' <= ch && ch <= 'R')
return
(2 * x + (
int
)(y));
else
return
((
int
)(2 * y) - x);
}
What is the output of the following Java statements?
System.out.println(mystery(5, 4.3, 'B'));
a.
System.out.println(mystery(4, 9.7, 'v'));
b.
System.out.println(2 * mystery(6, 3.9, 'D'));
c.
Search WWH ::
Custom Search