// (from the Carter book)
// Exercise 2.6(1). State the value and return type for each
// equation. Use the Math method given to output a value and
// then designate the return type for each equation.
public class MathMethodExercises1
{
public static void main (String[] args)
{
// Part (1a) -- Math.abs:
System.out.println (Math.abs (-5) - Math.abs (-7));
// return type is (negative) int
// Part (1b) -- Math.abs:
System.out.println (Math.abs (-1e-1) + Math.abs (-2e-2));
// return type is float
// Part (1c) -- Math.sqrt:
System.out.println (Math.sqrt (0.0064));
// return type is float
// Part (1d) -- Math.sqrt:
System.out.println (Math.sqrt (Math.pow (2.7, 2)));
// return type is float
// Part (1e) -- Math.round:
System.out.println (Math.round (3.499));
// return type is int (rounded value)
// Part (1f) -- Math.max:
System.out.println (Math.max (1.5e-2, 0.095));
// return type is float
// Part (1g) -- Math.ceil:
System.out.println (Math.ceil (4.002));
// return type is float (rounded-up value)
// Part (1h) -- Math.min:
System.out.println (Math.min (-5, 1.0));
// return type is float (if int is compared to float)
// Part (1i) -- Math.floor:
System.out.println (Math.floor (7.99));
// return type is float (rounded-down value)
// Part (1j) -- Math.ceil:
System.out.println (Math.ceil (-2.73));
// return type is (negative) float (rounded-up value)
// Part (1k) -- Math.pow:
System.out.println (Math.pow (16, 0.25));
// return type is float
// Part (1l) -- Math.pow:
System.out.println (Math.pow (4, -2));
// return type is float -- why is this?
// Part (1m) -- Math.round:
System.out.println (Math.round (1.49 + 0.1));
// return type is int (rounded value)
// Part (1n) -- Math.round:
System.out.println (Math.round (1.49) + 0.1);
// return type is float (int rounded value + float)
} // main method
} // MathMethodsExercises1 class
No comments:
Post a Comment