Java Reference
In-Depth Information
the Java console.
E3 . Write a procedure that prints the sum, difference, and product of its two
double parameters.
E4. Write a function that returns "Hooray" if one of its three arguments is less
than 10 and returns “Booo” otherwise.
E5. Write a procedure that prints "Hooray" in the Java console if one of its
three arguments is less than 10 and prints "Booo" otherwise.
E6. Write a function that computes the area of a circle, given its radius r . The
formula for the area is π r 2 . You can get π using Math.PI .
E7. Write a procedure that prints the area of a circle, given its radius r . The for-
mula for the area is π r 2 . You can get π using Math.PI .
E8. Write a function that, given the number of gallons of gas a tank can hold and
the fuel efficiency of the car (miles per gallon), calculates how far the car can go
on one tank of gas.
E9. Write a procedure that, given the number of gallons of gas a tank can hold
and the fuel efficiency of the car (miles per gallon), prints how far the car can go
on one tank of gas.
E10. Write a procedure with three parameters that prints, on separate lines of the
Java console, the smallest parameter, then the middle one, and finally the largest.
E11. Write a function that converts its parameter from miles to kilometers. One
mile equals 1.60935 kilometers. Use type double .
E12. Write a procedure that converts its parameter from kilometers to miles and
prints the result. One mile equals 1.60935 kilometers. Use type double .
E13. Write a function that converts its parameter from pounds to kilograms. One
pound equals 0.45359237 kilograms. Use type double .
E14. Write a procedure that converts its parameter from pounds to kilograms
and prints the result. One pound equals 0.45359237 kilograms. Use type double .
E15. Write a function that is given as parameters the number of hours, minutes,
and seconds of a time on a particular day and yields the total number of seconds
that the time represents.
E16. Write a function that is given an integer in the range 0..999999 and returns
it as a String, with a comma separating the last three digits from the first ones.
Of course, include the comma only if the number is at least 1000. For example,
for argument 1546 , the returned value is "1,546" , and for argument 34 , the
returned value is "34" .
E17. Write a procedure that is given a dollar amount and prints out how many
 
Search WWH ::




Custom Search