Tidying Up Java Basics--number&math class

Source: Internet
Author: User
Tags arithmetic cos sin square root

Java Number
Built-in data type: Byte int long short double, etc.

int i = 10;float i = 10.5f;

In practice, it is often encountered using objects rather than built-in data types, and wrapper classes (Integer Long Double Float Short) are subclasses of abstract class number
When the built-in data type is used as an object, the compiler will box the built-in type into a wrapper class

class Test{    public static void main(String[] args){        Integer i = 10;        i = i + 10;        System.out.println(i);    }}输出结果:20

I is assigned an integer value, I is boxed as an object.
To enable I to perform arithmetic operations, I will be unpacking
Java Math Class
Properties and methods that contain mathematical operations open square Absolute positive cotangent, etc.
Math is defined as a static form that can be called directly in the main function through the math class

class Test{    public static void main(String[] args){        System.out.println("90度的正弦值:" + Math.sin(Math.PI/2));        System.out.println("0度的余弦值:" + Math.cos(0));        System.out.println("60度的正切值:" + Math.tan(Math.PI/3));        System.out.println("1的反正切值:" + Math.atan(1));        System.out.println("π/2的角度值:" + Math.toDegrees(Math.PI/2));        System.out.println(Math.PI);    }}输出结果:90度的正弦值:1.00度的余弦值:1.060度的正切值:1.73205080756887671的反正切值:0.7853981633974483π/2的角度值:90.03.141592653589793

Common Number & Math classes



Method Description
Xxxvalue () Converts the number object to the value of the XXX data type and returns (does not accept any parameters: X.intvalue ())
CompareTo () To compare a number object to a parameter: int compareTo (parameter)
Equals () To determine if the number object is equal to a parameter, Boolean equals (Any object)
ValueOf () Returns the built-in data type specified by a number object (integer valueOf (int/string i)) or an integer valueOf (string s, number of binary)
ToString () Returns a value as a string.
parseint () Resolves a string to an int type.
ABS () Returns the absolute value of the parameter.
Ceil () Rounding an integer variable upward. The return type is of type double.
Floor () The integer variable is rounded down. The return type is of type double.
Rint () Returns the integer closest to the parameter. The return type is double.
Round () Returns the nearest int, Long value.
Min () Returns the minimum value from two parameters.
Max () Returns the maximum value in two parameters.
EXP () Returns the parameter of the base e of the natural number.
Log () Returns the value of the base of the natural number of the parameter. T
POW () Returns the second parameter of the first argument to the other side.
sqrt () The arithmetic square root of the argument.
Sin () Specifies the sine of a double type parameter.
cos () Specifies the cosine value of the double type parameter.
Tan () Specifies the tangent of a double type parameter.
ASIN () Specifies the inverse chord value of the double type parameter.
ACOs () Specifies the inverse cosine value of the double type parameter.
Atan () Specifies the inverse tangent value of the double type parameter.
ATAN2 () Converts Cartesian coordinates to polar coordinates and returns the angular value of the polar coordinates.
Todegrees () Converts a parameter to an angle.
Toradians () Converts the angle to radians.
Random () Returns a random number.

Tidying Up Java Basics--number&math class

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.