Java Number & Math class

Source: Internet
Author: User
Tags cos sin square root

Here is an instance that uses an Integer object:
Test.java File Code:
public class test{

public static void Main (String args[]) {
Integer x = 5;
x = x + 10;
SYSTEM.OUT.PRINTLN (x);
}
}
The results of the above example compilation run as follows:
15
When x is assigned an integer value, because X is an object, the compiler is boxing the X. Then, to allow X to be added, the X is disassembled.
Java Math Class
Java's math contains properties and methods for performing basic mathematical operations, such as elementary exponents, logarithms, square roots, and trigonometric functions.
The math method is defined as the static form, which can be called directly from the main function through the math class.
Test.java File Code:
public class Test {
Public bjrongjinhuiyin.com static void main (String []args)
{
System.out.println ("Sine of 90 degrees:" + Math.sin (MATH.PI/2));
System.out.println ("Cosine of 0 Degrees:" + math.cos (0));
System.out.println ("Tangent of 60 degrees:" + Math.tan (MATH.PI/3));
System.out.println ("1 of the inverse Tangent value:" + Math.atan (1));
System.out.println ("Π/2 angle value:" + math.todegrees (MATH.PI/2));
System.out.println (Math.PI);
}
}
The results of the above example compilation run as follows:
Sinusoidal value of 90 degrees: 1.0
Cosine of 0 Degrees: 1.0
Tangent of 60 degrees: 1.7320508075688767
1 of the inverse tangent value: 0.7853981633974483
Angle value of Π/2:90.0
3.141592653589793
Number & Math class methods
Some of the methods commonly used in the number & Math classes are listed in the following table:
Ordinal method and Description
1 Xxxvalue ()
Converts the number object to the value of the XXX data type and returns.
2 CompareTo ()
Compares a number object to a parameter.
3 Equals ()
Determines whether the number object is equal to the parameter.
4 ValueOf ()
Returns the built-in data type specified by a number object
5 toString ()
Returns a value as a string.
6 parseint ()
Resolves a string to an int type.
7 ABS ()
Returns the absolute value of the parameter.
8 Ceil ()
Rounding up the shape variable, the return type is double.
9 Floor ()
The integer variable is rounded down. The return type is of type double.
Ten 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.
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.
Java Branch Structure –if...else/switch Java Character class
List of Notes

Easier xbr/>502***[email protected]
< p="">

  • @author Dale.
  • Automatic boxing and unpacking in Java
  • To put it simply, the gold and silver container is the automatic conversion of the basic data type to the wrapper type; unpacking is the automatic conversion of the wrapper type to the base data type.
    */
    public class Number {
    public static void Main (string[] args) {
    /*
    Integer i1 = 128; Packing, equivalent to integer.valueof (128);
    int t = I1; Equivalent to I1.intvalue () unpacking
    System.out.println (t);
    /

    /**对于–128到127(默认是127)之间的值,被装箱后,会被放在内存里进行重用但是配资平台如果超出了这个值,系统会重新new 一个对象*/Integer i1 = 200;Integer i2 = 200;/**注意 == 与 equals的区别== 它比较的是对象的地址equlas 比较的是对象的内容*/if(i1==i2) {    System.out.println("true");} else {    System.out.println("false");}

    }br/>}
    Easier x
    Easier x
    502***[email protected]
    Miao
    zha***[email protected]

    Integer a = 10;
    Integer B = 10;
    System.out.println (A = = B); True
    System.out.println (A.equals (b)); True
    Integer a = 1000;
    Integer B = 1000;
    System.out.println (A = = B); False
    System.out.println (A.equals (b)); True

Java Number & Math class

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.