2022年8月4日,如何高效运用Java lang包Math类?

2026-06-10 07:231阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计489个文字,预计阅读时间需要2分钟。

2022年8月4日,如何高效运用Java lang包Math类?

描述:Java中util包下的Math类的使用,包括绝对值、随机数等。

效果展示:代码演示:javapackage test.day_01;

public class Demo2 { public static void main(String[] args) { System.out.println(绝对值: + Math.abs(-5)); System.out.println(随机数: + Math.random()); }}

描述:

Java中util包下的Math类的使用,含有绝对值,随机数等。。。

效果展示:

2022年8月4日,如何高效运用Java lang包Math类?

代码演示:

1
package test.day_01;

public class Demo2 {

public static void main(String[] args) {
System.out.println("随机数:"+Math.random());
System.out.println("绝对值:"+Math.abs(-1));
System.out.println("求和:"+Math.addExact(1, 2));
System.out.println("求次幂:"+Math.pow(2, 4));
System.out.println("较大值:"+Math.max(1, 4));
System.out.println("较小值:"+Math.min(1, 4));

// 两个固定值
System.out.println(Math.PI);
System.out.println(Math.E);
System.out.println("计算以e为底的对数:"+Math.log(Math.E));
System.out.println("计算以10为底的对数:"+Math.log10(100));
System.out.println("计算一个正数的平方根:"+Math.sqrt(16));
}
}
2
package test.day_01;

public class Demo1 {

public static void main(String[] args) {
// 随机获取一个数,小数,大于等于0,小于1
System.out.println(Math.random());
// 获取一个数的绝对值
System.out.println(Math.abs(-1));
// 计算两个数的和
System.out.println(Math.addExact(1, 2));
// 计算一个数的指定次方
System.out.println(Math.pow(2, 4));
// 返回两个数中的较大值
System.out.println(Math.max(1, 4));
// 返回两个数中的较小值
System.out.println(Math.min(1, 4));

// 两个固定值
System.out.println(Math.PI);
System.out.println(Math.E);
// 计算以e为底的对数
System.out.println(Math.log(Math.E));
// 计算以10为底的对数
System.out.println(Math.log10(100));
// 计算一个数(正数)的平方根
System.out.println(Math.sqrt(16));
}
}

本文共计489个文字,预计阅读时间需要2分钟。

2022年8月4日,如何高效运用Java lang包Math类?

描述:Java中util包下的Math类的使用,包括绝对值、随机数等。

效果展示:代码演示:javapackage test.day_01;

public class Demo2 { public static void main(String[] args) { System.out.println(绝对值: + Math.abs(-5)); System.out.println(随机数: + Math.random()); }}

描述:

Java中util包下的Math类的使用,含有绝对值,随机数等。。。

效果展示:

2022年8月4日,如何高效运用Java lang包Math类?

代码演示:

1
package test.day_01;

public class Demo2 {

public static void main(String[] args) {
System.out.println("随机数:"+Math.random());
System.out.println("绝对值:"+Math.abs(-1));
System.out.println("求和:"+Math.addExact(1, 2));
System.out.println("求次幂:"+Math.pow(2, 4));
System.out.println("较大值:"+Math.max(1, 4));
System.out.println("较小值:"+Math.min(1, 4));

// 两个固定值
System.out.println(Math.PI);
System.out.println(Math.E);
System.out.println("计算以e为底的对数:"+Math.log(Math.E));
System.out.println("计算以10为底的对数:"+Math.log10(100));
System.out.println("计算一个正数的平方根:"+Math.sqrt(16));
}
}
2
package test.day_01;

public class Demo1 {

public static void main(String[] args) {
// 随机获取一个数,小数,大于等于0,小于1
System.out.println(Math.random());
// 获取一个数的绝对值
System.out.println(Math.abs(-1));
// 计算两个数的和
System.out.println(Math.addExact(1, 2));
// 计算一个数的指定次方
System.out.println(Math.pow(2, 4));
// 返回两个数中的较大值
System.out.println(Math.max(1, 4));
// 返回两个数中的较小值
System.out.println(Math.min(1, 4));

// 两个固定值
System.out.println(Math.PI);
System.out.println(Math.E);
// 计算以e为底的对数
System.out.println(Math.log(Math.E));
// 计算以10为底的对数
System.out.println(Math.log10(100));
// 计算一个数(正数)的平方根
System.out.println(Math.sqrt(16));
}
}