math long取位_Java Math类静态long max(long l1,long l2)与示例

math long取位

数学类静态long max(long l1,long l2) (Math Class static long max(long l1,long l2) )

  • This method is available in java.lang package.

    此方法在java.lang包中可用。

  • This method is used to return the maximum one of both the given arguments in the method or in other words it returns the largest value of the given two arguments.

    此方法用于返回方法中两个给定参数中的最大值,换句话说,它返回给定两个参数中的最大值。

  • This is a static method so it is accessible with the class name too.

    这是一个静态方法,因此也可以使用类名进行访问。

  • The return type of this method is long, it returns the largest element from the given two arguments (which are of long types).

    此方法的返回类型为long ,它从给定的两个参数(均为long类型)中返回最大的元素。

  • In this method, we pass two long values (long) parameters as an argument.

    在此方法中,我们传递两个long值( long )参数作为参数。

  • This method does not throw any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    public static long max(long l1, long l2){
    }

Parameter(s): long l1, long l2 – two long values, in which we have to find the largest value.

参数: long l1,long l2 –两个长值,我们必须在其中找到最大值。

Return value:

返回值:

The return type of this method is long, it returns the largest/maximum value.

此方法的返回类型为long ,它返回最大值/最大值。

Note:

注意:

  • If we pass "NaN", it returns "NaN".

    如果我们传递“ NaN”,则返回“ NaN”。

  • If we pass the same value as both parameters, it returns the same value.

    如果我们为两个参数传递相同的值,则它将返回相同的值。

Java程序演示max(long l1,long l2)方法的示例 (Java program to demonstrate example of max(long l1, long l2) method)

// Java program to demonstrate the example of 
// max(long l1, long l2) method of Math Class

public class MaxLongTypeMethod {
    public static void main(String[] args) {
        // declaring variables
        long l1 = -0l;
        long l2 = 0l;
        long l3 = -2468l;
        long l4 = 12458l;

        // displaying values
        System.out.println("l1: " + l1);
        System.out.println("l2: " + l2);
        System.out.println("l3: " + l3);
        System.out.println("l4: " + l4);

        // Here , we will get (0) because we are 
        // passing parameter whose value is (-0l,0l)
        System.out.println("Math.max(l1,l2): " + Math.max(l1, l2));

        // Here , we will get (12458) and we are 
        // passing parameter whose value is (0l,12458l)
        System.out.println("Math.max(l2,l4): " + Math.max(l2, l4));
    }
}

Output

输出量

E:\Programs>javac MaxLongTypeMethod.java

E:\Programs>java MaxLongTypeMethod
l1: 0
l2: 0
l3: -2468
l4: 12458
Math.max(l1,l2): 0
Math.max(l2,l4): 12458


翻译自: https://www.includehelp.com/java/math-class-static-long-max-long-l1-long-l2-with-example.aspx

math long取位

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值