// CSE 142, Summer 2008 (Marty Stepp) // This program demonstrates the Math class and using return values. // public class MathExamples { public static void main(String[] args) { double power = Math.pow(4, 2); // returning a value System.out.println("the result is " + power); int age = 87; age = Math.max(Math.min(age, 40), 0); System.out.println("your age is " + age); double s1 = slope(0, 0, 6, 3); double s2 = slope(2, 1, 5, 2); System.out.println("The slope of the line is " + s1); System.out.println("The slope of the 2nd line is " + s2); System.out.println("The difference in slopes is " + (s1 - s2)); } // This method computes the slope of the line between the // points (x1, y1) and (x2, y2). public static double slope(int x1, int y1, int x2, int y2) { double dy = y2 - y1; double dx = x2 - x1; double result = dy / dx; return result; // result's value (0.5) is sent back to main } }