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

Info icon This 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 !
Image of page 1

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

View Full Document Right 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
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!
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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...
Image of page 6
return : Send a value out of a method the value can be used by the calling method.
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern