06-Return and Math (1).ppt - RETURN VALUES CS 103 BASIC JAVA PROGRAMS WITH PRINTLN STATEMENTS 1 JAVA'S MATH CLASS Method name Description Math.abs(value
06-Return and Math (1).ppt - RETURN VALUES CS 103 BASIC...
1CS 103BASIC JAVA PROGRAMS WITH PRINTLNSTATEMENTSRETURN VALUES
2JAVA'S MATHCLASSMethod nameDescriptionMath.abs(value)absolute valueMath.ceil(value)rounds upMath.floor(value)rounds downMath.log10(value)logarithm, base 10Math.max(value1,value2)larger of two valuesMath.min(value1,value2)smaller of two valuesMath.pow(base,exp)baseto the exppowerMath.random()random doublebetween 0 and 1Math.round(value)nearest whole numberMath.sqrt(value)square rootMath.sin(value)Math.cos(value)Math.tan(value)sine/cosine/tangent ofan angle in radiansMath.toDegrees(value)Math.toRadians(value)convert degrees toradians and backConstant DescriptionMath.E2.7182818...Math.PI3.1415926...
3CALLING MATHMETHODSMath.methodName(parameters)Examples:double squareRoot = Math.sqrt(121.0);System.out.println(squareRoot); // 11.0int absoluteValue = Math.abs(-50);System.out.println(absoluteValue); // 50System.out.println(Math.min(3, 7)+ 2); // 5The Mathmethods do not print to the console.Each method produces ("returns") a numeric result.The results are used as expressions (printed, stored, etc.).
4RETURNreturn: To send out a value as the result of a method.The opposite of a parameter:Parameters send information in from the caller to the method.Return values send information out from a method to its caller.