Math Class Your favorite class!.

Slides:



Advertisements
Similar presentations
Methods Java 5.1 A quick overview of methods
Advertisements

Data types, declarations, and expressions in Java.
©2004 Brooks/Cole Chapter 3 Assignment. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Assignment In the last chapter we learned how to declare.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
Microsoft® Small Basic The Math Object Estimated time to complete this lesson: 1 hour.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
Topic 12 more if/else, cumulative algorithms, printf Copyright Pearson Education, 2010 Based on slides bu Marty Stepp and Stuart Reges from
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
Copyright © Curt Hill Mathematics Functions An example of static methods.
© 2012 EMC Publishing, LLC Slide 1 Chapter 7 The Math Class  Includes shared methods that perform common math functions.  Math Class methods include:
Chapter 5: Methods 1. Objectives To declare methods, invoke methods, and pass arguments to a method (§ ). To use method overloading and know ambiguous.
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 4 Mathematical Functions, Characters,
Building Java Programs Chapter 3 Parameters and Objects Copyright (c) Pearson All rights reserved.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
Functions & Libraries. Introduction Functions – Modules of code Uses – Abstraction Build complex tasks with simpler ones Don't worry about details at.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
BY: MARIAH & JON 13.4 INVERSE OF SINE AND TANGENT.
Lecture 10:Static & Final Kenya © 2005 MIT-Africa Internet Technology Initiative MyMath Example public class MyMath { public double PI = ;
Python Functions : chapter 3
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
The Math Class Methods Utilizing the Important Math Operations of Java!
1 Java Library Lecture 9 by Dr. Norazah Yusof. 2 Java Library Java has pre-defined classes that consist of the basic language classes in Java (organized.
MIT AITI 2004 Lecture 10 Static and Final. public class MyMath { public double PI = ; public double square (double x) { return x * x; } public.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6A Methods (Concepts)
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
Lecture 5: java.lang.Math, java.lang.String and Characters Michael Hsu CSULA.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double.
Chapter 4 Mathematical Functions, Characters, and Strings 1.
14.0 Math Review 14.1 Using a Calculator Calculator
Chapter 4 Mathematical Functions, Characters, and Strings
Week 3 - Wednesday CS 121.
Lecture 6: While Loops and the Math Class
2.1 Classifying Polynomials
Chapter 4 Mathematical Functions, Characters, and Strings
Building Java Programs
25 Math Review Part 1 Using a Calculator
SEEM4570 Tutorial 05: JavaScript as OOP
Additional Topics in math Lessons 5-7
Chapter 3 Methods.
Chapter 5 – Part 2 Methods Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Working with Text and Numbers in Java
Building Java Programs
Chapter 4: Mathematical Functions, Characters, and Strings
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
7. Roots and Radical Expressions
Java's Math class Method name Description Math.abs(value)
7.5 Solving Radical Equations
METHODS (FUNCTIONS) By: Lohani Adeeb khan.
Chapter 5 Methods.
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
Building Java Programs
Chapter 5 Methods Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
CSE 142 Lecture Notes Global Constants, Parameters, Return Values
What is the number whose area is 16 unit square?
Powerful Numbers I am learning to solve multiplication problems with powers (exponents). e.g. 22 or 23.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Warm-Up Algebra 2 Honors 2/12/18
Objective 7.03 Apply Built-in Math Class Functions
Ch 5 : Mathematical Functions, Characters, and Strings
Presentation transcript:

Math Class Your favorite class!

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 (https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html). But lets go through some of the more useful one.

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 6.283185307179586 and var2 will store 0.2718281828459045.

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.

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.