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 :
import java.math.RoundingMode;
import com.google.common.math.IntMath;
class GFG {
public static void main(String args[])
{
int x = 1542 ;
int y = 421 ;
int ans = IntMath.mean(x, y);
System.out.println( "Mean of " + x + " and "
+ y + " is : " + ans);
}
}
|
Output :
Mean of 1542 and 421 is : 981
Example 2 :
import java.math.RoundingMode;
import com.google.common.math.IntMath;
class GFG {
public static void main(String args[])
{
int x = 214 ;
int y = 154 ;
int ans = IntMath.mean(x, y);
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-
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!