java int numbers_Java - Numbers Class 数值类

Java - Numbers Class

573d09710291

Number Methods

NO.

Method && Description

1

xxxValue()
转换为指定类型的值

2

compareTo()
比较值的大小

3

equals()
判断大小

4

valueOf()
返回一个整数对象并且持有指定的值

5

toString()
返回一个字符串对象代表当前指定的int or integer

6

parseInt()
方法用于格式化一些字符串返回整数

7

abs()
求绝对值

8

ceil()
向上取整 , 返回double

9

floor()
向下取整, 返回 double

10

rint()
四舍五入取整数,返回double

11

round()
四舍五入

12

min()
取最小值

13

max()
取最大值

14

exp()
对数e的计算

15

log()
返回自然的对数

16

pow()
阶运算,第一个参数做底数,第二参数做阶数

17

sqrt()
获取平方根

18

sin()
正弦

19

cos()
余弦

20

tan()
正切

21

asin()
反正弦

22

acos()
反余弦

23

atan()
反正切

24

atan2()
直角坐标转换为极坐标

25

toDegrees()
转换为角度

26

toRadians()
转换为弧度

27

random()
随机数

Example

public class Methods {

public static void main(String[] args) {

Integer x = 8;

// XXXValue()

System.out.println("Number.xxxValue()");

// return byte primitive data type

System.out.println(x.byteValue());

// return double primitive data type

System.out.println(x.doubleValue());

// return long primitive data type

System.out.println(x.longValue());

// compareTo();

System.out.println("Number.compareTo()");

// return 1

System.out.println(x.compareTo(6));

// return 0

System.out.println(x.compareTo(8));

// return -1

System.out.println(x.compareTo(10));

// equals()

System.out.println("Number.equals()");

Integer y = 8;

Integer z = 9;

short h = 8;

String m = "8";

System.out.println(x.equals(y));

System.out.println(x.equals(z));

System.out.println(x.equals(h));

System.out.println(x.equals(m));

// valueOf()

System.out.println("Number.valueOf()");

System.out.println(Double.valueOf("99"));

System.out.println(Float.valueOf("90"));

System.out.println(Long.valueOf("999"));

System.out.println(Integer.valueOf("9", 16));

// toString

System.out.println("Number.toString()");

String s1 = Integer.toString(8);

System.out.println(s1 instanceof String);

// parseInt()

System.out.println("parseInt()");

System.out.println(Integer.parseInt("666"));

System.out.println(Double.parseDouble("888"));

System.out.println(Float.parseFloat("777"));

// abs()

System.out.println("Math.abs()");

System.out.println(Math.abs(Integer.parseInt("-99")));

System.out.println(Math.abs(Double.parseDouble("-88.88")));

// ceil() return double type

double d1 = -100.81;

float f1 = 99;

System.out.println("Math.ceil()");

System.out.println(Math.ceil(d1));

System.out.println(Math.ceil(f1));

// floor()

System.out.println("Math.floor()");

System.out.println(Math.floor(-99.99));

System.out.println(Math.floor(88.10));

// rint()

System.out.println("Math.rint()");

System.out.println(Math.rint(99.1));

System.out.println(Math.rint(99.5));

System.out.println(Math.rint(99.6));

// round()

System.out.println("Math.round()");

System.out.println(Math.round(99.1));

System.out.println(Math.round(99.9));

// min()

System.out.println("Math.min()");

System.out.println(Math.min(11, 44.1));

// max()

System.out.println("Math.max()");

System.out.println(Math.max(11, 44.1));

// exp() 对数

System.out.println("Math.exp()");

System.out.println(Math.E);

System.out.println(Math.exp(2));

// log()

System.out.println("Math.log()");

System.out.println(Math.log(7.39));

// pow

System.out.println("Math.pow");

System.out.println(Math.pow(2, 5));

// sqrt

System.out.println("Math.sqrt");

System.out.println(Math.sqrt(2));

// sin

double degrees = 60.0;

double radians = Math.toRadians(degrees);

System.out.println("Math.sin()");

System.out.println(radians);

System.out.println(Math.sin(radians));

System.out.println(Math.sqrt(3) / 2);

// cos

System.out.println("Math.cos()");

System.out.println(Math.cos(radians));

// tan

System.out.println("Math.tan()");

System.out.println(Math.tan(radians));

// asin

System.out.println("Math.asin()");

System.out.println(Math.asin(Math.sin(radians)) == radians);

// acos

System.out.println("Math.acos()");

System.out.println(Math.acos(Math.cos(radians)) == radians);

// atan

System.out.println("Math.atan()");

System.out.println(Math.atan(Math.tan(radians)) == radians);

// atan2

System.out.println("Math.atan2()");

System.out.println(Math.atan2(30, 45));

//toDegrees

System.out.println("Math.toDegrees()");

System.out.println(Math.round(Math.toDegrees(radians)));

//toRadians

System.out.println("Math.toRadians()");

System.out.println(Math.toRadians(degrees));

//random

System.out.println("Math.random()");

System.out.println(Math.round(Math.random() * 1000 + 1));

}

}

Output

Number.xxxValue()

8

8.0

8

Number.compareTo()

1

0

-1

Number.equals()

true

false

false

false

Number.valueOf()

99.0

90.0

999

9

Number.toString()

true

parseInt()

666

888.0

777.0

Math.abs()

99

88.88

Math.ceil()

-100.0

99.0

Math.floor()

-100.0

88.0

Math.rint()

99.0

100.0

100.0

Math.round()

99

100

Math.min()

11.0

Math.max()

44.1

Math.exp()

2.718281828459045

7.38905609893065

Math.log()

2.0001277349601105

Math.pow

32.0

Math.sqrt

1.4142135623730951

Math.sin()

1.0471975511965976

0.8660254037844386

0.8660254037844386

Math.cos()

0.5000000000000001

Math.tan()

1.7320508075688767

Math.asin()

true

Math.acos()

true

Math.atan()

true

Math.atan2()

0.5880026035475675

Math.toDegrees()

60

Math.toRadians()

1.0471975511965976

Math.random()

199

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值