常用的数学运算有哪些,比如取整、取绝对值、保留几位小数?

2026-05-26 02:440阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

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

常用的数学运算有哪些,比如取整、取绝对值、保留几位小数?

javapublic class Main { public static void main(String[] args) { System.out.println(Math.max(1, 2)); System.out.println(Math.min(1, 2)); System.out.println(Math.abs(-1)); }}

返回两个数的最大值(支持int long float double)

System.out.println(Math.max(1,2));

返回两个数的最小值(支持int long float double)

System.out.println(Math.min(1,2));

返回一个数的绝对值(支持int long float double)

System.out.println(Math.abs(-15.6));

返回一个数四舍五入后取整(支持float double)注意, float型取整后是int型,而double取整后是long型。

阅读全文

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

常用的数学运算有哪些,比如取整、取绝对值、保留几位小数?

javapublic class Main { public static void main(String[] args) { System.out.println(Math.max(1, 2)); System.out.println(Math.min(1, 2)); System.out.println(Math.abs(-1)); }}

返回两个数的最大值(支持int long float double)

System.out.println(Math.max(1,2));

返回两个数的最小值(支持int long float double)

System.out.println(Math.min(1,2));

返回一个数的绝对值(支持int long float double)

System.out.println(Math.abs(-15.6));

返回一个数四舍五入后取整(支持float double)注意, float型取整后是int型,而double取整后是long型。

阅读全文