Java Guava | mean(long x, long y) of LongMath Class with Examples
The mean(long x, long y) method of Guava’s LongMath Class accepts two parameters x and y and calculates arithmetic mean of them rounded towards negative infinity. This method is overflow resilient.
Syntax:
public static long mean(long x, long y)
Parameters: This method accepts two parameters x and y which are of long type.
Return Value: The method returns arithmetic mean of x and y, rounded towards negative infinity.
Exceptions: The method doesn’t have any exception.
Example 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
Example 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
Recommended Posts:
- Java Guava | mod(long x, long m) of LongMath Class with Examples
- Java Guava | gcd(long a, long b) of LongMath Class with Examples
- Java Guava | pow(long b, int k) of LongMath Class with Examples
- Java Guava | isPowerOfTwo(long x) of LongMath Class with Examples
- Java Guava | log2(long x, RoundingMode mode) of LongMath Class with Examples
- Java Guava | sqrt(long x, RoundingMode mode) of LongMath Class with Examples
- Java Guava | LongMath.divide(long, long, RoundingMode) method with Examples
- Java Guava | LongMath.checkedAdd(long a, long b) method with Examples
- Java Guava | LongMath.checkedPow(long b, int k) method with Examples
- Java Guava | LongMath log10(long x, RoundingMode mode) method with Examples
- Java Guava | binomial(int n, int k) of LongMath Class with Examples
- LongMath Class | Guava | Java
- Java Guava | LongMath.checkedMultiply(int a, int b) method with Examples
- Java Guava | Longs.checkedSubtract(long a, long b) method with Examples
- Java Guava | Longs.indexOf(long[] array, long target) method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



