Guava LongMath类的mean(long x,long y)方法接受两个参数x和y,并计算它们的算术平均值,取整为负无穷大。此方法具有溢出弹性。
用法:
public static long mean(long x, long y)
参数:此方法接受长类型的两个参数x和y。
返回值:该方法返回x和y的算术平均值,四舍五入为负无穷大。
异常:该方法没有任何异常。
范例1:
// Java code to show implementation of
// mean(long x, long y) method of Guava's
// LongMath class
import java.math.RoundingMode;
import com.google.common.math.LongMath;
class GFG {
// Driver code
public static void main(String args[])
{
long x = 1542;
long y = 421;
// Using mean(long x, long y)
// method of Guava's LongMath class
long ans = LongMath.mean(x, y);
// Displaying the result
System.out.println("Mean of " + x + " and "
+ y + " is:" + ans);
}
}
输出:
Mean of 1542 and 421 is:981
范例2:
// Java code to show implementation of
// mean(long x, long y) method of Guava's
// LongMath class
import java.math.RoundingMode;
import com.google.common.math.LongMath;
class GFG {
// Driver code
public static void main(String args[])
{
long x = 65;
long y = 41;
// Using mean(long x, long y)
// method of Guava's LongMath class
long ans = LongMath.mean(x, y);
// Displaying the result
System.out.println("Mean of " + x + " and "
+ y + " is:" + ans);
}
}
输出:
Mean of 65 and 41 is:53
相关用法
- Java Guava LongMath gcd(long a, long b)用法及代码示例
- Java Guava LongMath mod(long x, long m)用法及代码示例
- Java Guava LongMath pow(long b, int k)用法及代码示例
- Java Guava LongMath isPowerOfTwo(long x)用法及代码示例
- Java Guava LongMath sqrt(long x, RoundingMode mode)用法及代码示例
- Java LongMath.divide(long, long, RoundingMode)用法及代码示例
- Java LongMath.checkedAdd(long a, long b)用法及代码示例
- Java LongMath.checkedPow(long b, int k)用法及代码示例
- Java LongMath log10(long x, RoundingMode mode)用法及代码示例
- Java Guava LongMath binomial(int n, int k)用法及代码示例
- Java LongMath.checkedMultiply(int a, int b)用法及代码示例
- Java Longs.checkedSubtract(long a, long b)用法及代码示例
- Java Longs.indexOf(long[] array, long[] target)用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 Java Guava | mean(long x, long y) of LongMath Class with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。