Ch03-2 - Java Section 3.2 Methods give back ! Expressions...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Section 3.2 Methods give back !
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Expressions give back values int num1 = 10; int num2 = 20; int num3 = 30; System.out.println(num1 + num2 + num3); Just output, not kept for further use int sum = num1 + num2 + num3; Not output, but available for further use
Background image of page 2
Methods give back values Like math functions -- Suppose f(x) = 3x 2 + 5x – 7 What does this mean? y = f(4) / 3 The result of f(4) is used in the second expression!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Math class Some useful methods that give back values Example 1.732. .. Math.sqrt(3.0) To use System.out.println(Math.sqrt(3.0)); // output double root = Math.sqrt(3.0); // keep for later
Background image of page 4
Math method name Description abs( value ) absolute value ceil( value ) rounds up cos( value ) cosine, in radians floor( value ) rounds down log( value ) logarithm base e log10( value ) logarithm base 10 max( value1 , value2 ) larger of two values min( value1 , value2 ) smaller of two values pow( base , exponent ) base to the exponent power random() random double between 0 and 1 round( value ) nearest whole number sin( value ) sine, in radians sqrt( value ) square root
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Math class Has some useful values, too Math.E Math.PI What does the style imply? Constant Description E 2.7182818. .. PI 3.1415926. ..
Background image of page 6
return : Send a value out of a method the value can be used by the calling method. A return is like the opposite of a parameter:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/15/2010 for the course COMPSCI Comp 142 taught by Professor Topham during the Spring '06 term at Shoreline.

Page1 / 17

Ch03-2 - Java Section 3.2 Methods give back ! Expressions...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online