Java Reference
In-Depth Information
m.
13 + Math.abs(-7) - Math.pow(2, 3) + 5
n.
Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))
o.
7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5))
p.
Math.max(18 - 5, Math.ceil(4.6 * 3))
11.
What output is produced by the following program?
1
public class
MysteryReturn {
2
public static void
main(String[] args) {
3
int
x = 1, y = 2, z = 3;
4 z = mystery(x, z, y);
5 System.out.println(x + " " + y + " " + z);
6 x = mystery(z, z, x);
7 System.out.println(x + " " + y + " " + z);
8 y = mystery(y, y, z);
9 System.out.println(x + " " + y + " " + z);
10 }
11
12
public static int
mystery(
int
z,
int
x,
int
y) {
13 z--;
14 x = 2 * y + z;
15 y = x - 1;
16 System.out.println(y + " " + z);
17
return
x;
18 }
19 }
12.
Write a method called
min
that takes three integers as parameters and returns the smallest of the three values; for
example, a call of
min(3, -2, 7)
would return
2,
and a call of
min(19, 27, 6)
would return
6.
Use
Math.min
to write your solution.
13.
Write a method called
countQuarters
that takes an
int
representing a number of cents as a parameter and returns
the number of quarter coins represented by that many cents. Don't count any whole dollars, because those would be
dispensed as dollar bills. For example,
countQuarters(64)
would return 2, because 64 cents is equivalent to 2 quar-
ters with 14 cents left over. A call of
countQuarters(1278)
would return 3, because after the 12 dollars are taken
out, 3 quarters remain in the 78 cents that are left.
Section 3.3: Using Objects
14.
Assuming that the following variables have been declared:
String str1 = "Q.E.D.";
String str2 = "Arcturan Megadonkey";
String str3 = "Sirius Cybernetics Corporation";
evaluate the following expressions:
a.
str1.length()
b.
str2.length()
c.
str1.toLowerCase()
Search WWH ::
Custom Search