Java Beginner: Built-in functions to calculate simple mathematical expressions

Source: Internet
Author: User
Tags sin square root

This should have been written before, forgotten, and mended.

This time we talk about how to compute the values of mathematical expressions in Java, for example, we want to calculate sin (PI/3) + cos (PI/6) + 5.6^3, how do we calculate it? Here we need to use the Java math built-in function, the so-called built-in function, is the Java has given you the method, you use the good, sometimes you need to import the package yourself, but math is not, Java will automatically import, do not have to manually import. Let's take a look at this example:

Compile and run through, no problem, this is very simple.

Math.PI, is sent, Math.pow (Z, 3), is to calculate the cubic of Z, Math.sin (x), is sin (x), subtraction these, and mathematics, but some methods and functions need to use the built-in function to achieve, math there are many ways, In this case, it is common to have sqrt (x) (square root), ABS (x) (absolute value), Max (x, y) (maximum in two numbers), min (x, y) (the smallest of two numbers), and so on.

This is relatively simple, is to use Java to express a simple mathematical expression, deep down may be some trouble, but also just because you do not know some of the use of built-in functions, but the truth is very simple, there is a mathematical expression, give you the value of the function, you put the number in, to find the result is good.

Java Beginner: Built-in functions to calculate simple mathematical expressions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.