Java Guava | mean(long x, long y) of LongMath Class with Examples Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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); } } Output: Mean of 1542 and 421 is : 981 Example 2: Java // 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); } } Output: Mean of 65 and 41 is : 53 Reference: https://google.github.io/guava/releases/20.0/api/docs/com/google/common/math/LongMath.html#mean-long-long- Comment More infoAdvertise with us Next Article Java Guava | mean(long x, long y) of LongMath Class with Examples S Sahil_Bansall Follow Improve Article Tags : Java Java-Functions java-guava Guava-LongMath Practice Tags : Java Similar Reads Java Guava | mod(long x, long m) of LongMath Class with Examples The mod(long x, long m) method of Guava's LongMath Class accepts two parameters x and m, and used to calculate the value of x modulus under m. Syntax: public static long mod(long x, long m) Parameters: This method accepts two parameters x and m which are of long type to calculate x modulo m. Return 2 min read Java Guava | gcd(long a, long b) of LongMath Class with Examples The method gcd(long a, long b) of Guava's LongMath Class returns the greatest common divisor of two parameters a and b. Syntax: public static long gcd(long a, long b) Parameters: This method accepts two parameters a and b of the long type of whose GCD is to be found. Return Type: This method returns 2 min read Java Guava | log2(long x, RoundingMode mode) of LongMath Class with Examples The method log2(long x, RoundingMode mode) of Guava's LongMath Class accepts two parameters and calculates the base-2 logarithmic value of the first parameter rounded according to the rounding mode specified by the second parameter. Syntax: public static int log2(long x, RoundingMode mode) Parameter 3 min read Java Guava | isPowerOfTwo(long x) of LongMath Class with Examples The method isPowerOfTwo(long x) of Guava's LongMath Class is used to check if a number is power of two or not. It accepts the number to be checked as a parameter and return boolean value true or false based on whether the number is a power of 2 or not. Syntax: public static boolean isPowerOfTwo(long 2 min read Java Guava | LongMath.checkedAdd(long a, long b) method with Examples The checkedAdd(long a, long b) is a method of Guava's LongMath Class which accepts two parameters a and b, and returns their sum. Syntax: public static long checkedAdd(long a, long b) Parameters: The method accepts two long values a and b and computes their sum. Return Value: The method returns the 2 min read Like