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...

This preview shows page 1 - 5 out of 17 pages.

1 CS 103 BASIC JAVA PROGRAMS WITH PRINTLN STATEMENTS RETURN VALUES
Image of page 1
2 JAVA'S MATH CLASS Method name Description Math.abs( value ) absolute value Math.ceil( value ) rounds up Math.floor( value ) rounds down Math.log10( value ) logarithm, base 10 Math.max( value1 , value2 ) larger of two values Math.min( value1 , value2 ) smaller of two values Math.pow( base , exp ) base to the exp power Math.random() random double between 0 and 1 Math.round( value ) nearest whole number Math.sqrt( value ) square root Math.sin( value ) Math.cos( value ) Math.tan( value ) sine/cosine/tangent of an angle in radians Math.toDegrees( value ) Math.toRadians( value ) convert degrees to radians and back Constant Description Math.E 2.7182818... Math.PI 3.1415926...
Image of page 2
3 CALLING MATH METHODS Math. methodName ( parameters ) Examples: double squareRoot = Math.sqrt(121.0) ; System.out.println(squareRoot); // 11.0 int absoluteValue = Math.abs(-50) ; System.out.println(absoluteValue); // 50 System.out.println( Math.min(3, 7) + 2); // 5 The Math methods do not print to the console. Each method produces ("returns") a numeric result. The results are used as expressions (printed, stored, etc.).
Image of page 3
4 RETURN return : 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.
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 17 pages?

  • Winter '20

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture