Download presentation
Presentation is loading. Please wait.
1
Math Class Your favorite class!
2
What is it JAVA provides a lot of useful classes that you can make use of to accomplish various tasks. Some of these we have already made use of like the System class and the Scanner class. If you are performing complex mathematical calculations then the Math class provides many useful tools. A complete listing can be found in the Math API ( But lets go through some of the more useful one.
3
Constants The Math class has two constants. They are pi and e. Code example: double var1 = 2 * Math.PI; double var2 = Math.E / 10; After this code is executed, var1 will store and var2 will store
4
Methods The Math class an absolute value method, a square root method, an exponent method, trig methods (both regular and inverse), and a log function (both base e and base 10). Code example: double var3 = Math.abs(-7); double var4 = Math.sqrt(16); double var5 = Math.pow(2, 5); double var6 = Math.sin(Math.PI/2); double var7 = Math.log10(1000); After this code is executed, var3 will store 7, var4 will store a 4, var5 will store 32, and var6 will store a 1, and var7 will store a 3.
5
Methods – Important Notes
Square Root Method – if a negative number is passed in then the result will be NaN. NaN is a specified value that is considered to be not a number. It will result in other NaN values when you try and use it in other calculations. Trig Methods – these methods are set up to work with radians and not degrees. There is a toDegrees and a toRadians method that can help you to convert quickly back and forth.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.