Java Reference
In-Depth Information
14 public static void carbonated(String coke, String soda, String pop) {
15 System.out.println("say " + soda + " not " + pop + " or " + coke);
16 }
17 }
7. Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints
that String the given number of times with a space after each time. For example, the call
printStrings("abc", 5);
will print the following output:
abc abc abc abc abc
8. The System.out.println command works on many different types of values, such as integers or doubles. What is
the term for such a method?
Section 3.2: Methods That Return Values
9. What is wrong with the following program?
1 public class Temperature {
2 public static void main(String[] args) {
3 double tempf = 98.6;
4 double tempc = 0.0;
5 ftoc(tempf, tempc);
6 System.out.println("Body temp in C is: " + tempc);
7 }
8
9 // converts Fahrenheit temperatures to Celsius
10 public static void ftoc( double tempf, double tempc) {
11 tempc = (tempf - 32) * 5 / 9;
12 }
13 }
10. Evaluate the following expressions:
a. Math.abs(-1.6)
b. Math.abs(2 + -4)
c. Math.pow(6, 2)
d. Math.pow(5 / 2, 6)
e. Math.ceil(9.1)
f. Math.ceil(115.8)
g. Math.max(7, 4)
h. Math.min(8, 3 + 2)
i. Math.min(-2, -5)
j. Math.sqrt(64)
k. Math.sqrt(76 + 45)
l. 100 + Math.log10(100)
Search WWH ::




Custom Search