Saturday, October 25, 2025
HomeLanguagesJavaJava Guava | mean() method of IntMath Class

Java Guava | mean() method of IntMath Class

The mean(int x, int y) method of Guava’s IntMath 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 int mean(int x, int y)

Parameters: This method accepts two parameters x and y which are of integer types.

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(int x, int y) method of Guava's
// IntMath class
import java.math.RoundingMode;
import com.google.common.math.IntMath;
  
class GFG {
  
    // Driver code
    public static void main(String args[])
    {
        int x = 1542;
        int y = 421;
  
        // Using mean(int x, int y)
        // method of Guava's IntMath class
        int ans = IntMath.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 code to show implementation of
// mean(int x, int y) method of Guava's
// IntMath class
import java.math.RoundingMode;
import com.google.common.math.IntMath;
  
class GFG {
  
    // Driver code
    public static void main(String args[])
    {
        int x = 214;
        int y = 154;
  
        // Using mean(int x, int y)
        // method of Guava's IntMath class
        int ans = IntMath.mean(x, y);
  
        // Displaying the result
        System.out.println("Mean of " + x + " and " 
                                 + y + " is : " + ans);
    }
}


Output :

Mean of 214 and 154 is : 184

Reference :
https://google.github.io/guava/releases/20.0/api/docs/com/google/common/math/IntMath.html#mean-int-int-

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS