// Helene Martin, CSE 142 // Demonstrates usage of Math methods and type casting public class MathDemo { public static void main(String[] args) { double power = (int) Math.pow(10, 3); System.out.println(power); double average = (double) (3 + 2) / 2; System.out.println(average); int age = 12; System.out.println(Math.min(Math.max(age, 0), 40)); double s = slope(4, 5, 7, 13); System.out.println("Slope: " + round2(s, 3)); } public static double round2(double value, int places) { double rounded = Math.round(value * Math.pow(10, places)) / Math.pow(10, places); return rounded; } // calculates the slope of the line through (x1, y1) (x2, y2) public static double slope(int x1, int y1, int x2, int y2) { int dy = y2 - y1; int dx = x2 - x1; double slope = (double) dy / dx; return slope; } }