Java.lang.math.max()函数是Java中的内置函数,该函数最多返回两个数字。参数以int,double,float和long的形式接受,如果传递负数和正数作为参数,则生成正数结果。如果两个参数传递的都是负数,那么将生成幅度较小的数字。

用法:

dataType max(dataType num1, dataType num2)

The datatypes can be int, float, double or long.

参数: The function accepts two parameters num1 and num2

among which the maximum is returned

返回值:该函数最多返回两个数字。数据类型将与参数相同。

下面给出的是函数max()的示例

// Java program to demonstrate the use of max() function

// when two double data-type numbers are

// passed as arguments

public class Gfg {

public static void main(String args[])

{

double a = 12.123;

double b = 12.456;

// prints the maximum of two numbers

System.out.println(Math.max(a, b));

}

}

输出:

12.456

// Java program to demonstrate the use of max() function

// when one positive and one negative

// integers are passed as argument

public class Gfg {

public static void main(String args[])

{

int a = 23;

int b = -23;

// prints the maximum of two numbers

System.out.println(Math.max(a, b));

}

}

输出:

23

// Java program to demonstrate the use of max() function

// when two negative integers are passed as argument.

public class Gfg {

public static void main(String args[])

{

int a = -25;

int b = -23;

// prints the maximum of two numbers

System.out.println(Math.max(a, b));

}

}

输出:

-23

java max 函数_Java Math max()用法及代码示例相关推荐

  1. java使用abs函数_Java Math abs()用法及代码示例

    java.lang.Math.abs()返回给定参数的绝对值. 如果参数不为负,则返回参数. 如果参数为负,则返回参数的取反. 用法: public static DataType abs(DataT ...

  2. java atomiclong 使用_Java AtomicLong set()用法及代码示例

    Java.util.concurrent.atomic.AtomicLong.set()是Java中的内置方法,可更新先前的值并将其设置为在参数中传递的新值. 用法: public final voi ...

  3. java dictionary 实例化_Java Dictionary put()用法及代码示例

    字典的put()方法用于在字典中插入映射.这意味着可以将特定键及其值映射到特定字典中. 用法: DICTIONARY.put(key, value) 参数:该方法有两个参数,都属于Dictionary ...

  4. java的round函数怎么用_Java Math round()用法及代码示例

    java.lang.Math.round()是内置数学函数,它返回最接近参数的long.通过将1/2相加,将结果四舍五入为整数,再加上1/2后取结果的下限,并将结果强制转换为long类型. 如果参数为 ...

  5. java math.sin()_Java Math sin()用法及代码示例

    java.lang.Math.sin()返回介于0.0和pi之间的角度的三角正弦.如果参数为NaN或无穷大,则结果为NaN.如果自变量为零,则结果为零,其符号与自变量相同.返回的值将在-1和1之间. ...

  6. java scanner字符串_Java Scanner toString()用法及代码示例

    java.util.Scanner类的toString()方法返回此Scanner的字符串表示形式.未指定确切的格式. 用法: public String toString() 返回值:此函数返回此扫 ...

  7. java 中negate()_Java BigInteger negate()用法及代码示例

    先决条件:BigInteger基础 的java.math.BigInteger.negate()方法返回一个BigInteger,其值为(-this). negate()方法将更改BigInteger ...

  8. java numberformat 方法_Java NumberFormat parse()用法及代码示例

    parse(str)方法是java.text.NumberFormat的内置方法,该方法从给定字符串的开头解析文本以产生数字.该方法可能不使用给定字符串的整个文本 用法: public Number ...

  9. java hashtable 遍历_Java HashTable forEach()用法及代码示例

    Hashtable类的forEach(BiConsumer)方法对哈希表的每个条目执行BiConsumer操作,直到已处理完所有条目或该操作引发异常. BiConsumer操作是按迭代顺序执行的哈希表 ...

  10. java mkdir 使用_Java File mkdir()用法及代码示例

    mkdir()方法是File类的一部分. mkdir()函数用于创建由抽象路径名表示的新目录.如果创建目录,则该函数返回true,否则返回false. 函数签名: public boolean mkd ...

最新文章

  1. Java注解是如何工作的?
  2. 数学图形(2.19) 利萨茹3D曲线
  3. 自定义控件的时候为控件增加事件
  4. 超图js版本添加矢量图层并在图层上绘一个面要素
  5. php输出pre自动换行,解决 html pre 标签的内容自动换行的问题
  6. 使用vmware converter转物理机linux的问题
  7. python怎么对齐文件_说说在 python 中,如何对齐文本
  8. 前端基础-html-列表
  9. c语言中next如何用,c语言的数据结构中,next是如何指向下一个元素的?
  10. Poj(2679),SPFA,邻接表(主流写法)
  11. Android基本界面控件六-进度条
  12. sql 时间字符串转换
  13. 2009年1月高等教育国际金融全国统一命题考试
  14. 中小企业如何才能招聘到合适的程序员?
  15. 游戏开发中的矩阵与变换
  16. 【设计原则】里氏代换原则
  17. 语义分割yolov5 v4.0 baseline快速复现 快速跑通 图像分割 图像分类 重新训练,训练结果,测试结果,实验图片-20210227
  18. Remove Double Negative(去除双重否定)
  19. 输入电阻和输出电阻的区别
  20. 深度学习 笔记(线性神经网络)

热门文章

  1. AVX图像算法优化系列二: 使用AVX2指令集加速查表算法。
  2. Jmeter之接口测试流程详解
  3. Python:混合动力汽车能量管理_动态规划简版(1/2)
  4. 微信小程序——轮播图
  5. 2022CCPC网络预选赛题解
  6. ORACLE 锁解释
  7. HTML5 如何让背景图片自适应浏览器大小
  8. 微信小程序商城项目实战(第八篇:我的界面)
  9. java计算机毕业设计教务管理系统源码+mysql数据库+系统+lw文档+部署
  10. tomcat:日志配置详解(避免日志过多撑爆磁盘)