Compute average of two numbers without overflow | Java code to compute average of two numbers ; Function to compute average of two numbers ; Driver code ; Assigning maximum integer value ; Average of two equal numbers is the same number ; Function to get the average of 2 numbers
import java . io . * ; class GFG { static int compute_average ( int a , int b ) { return ( a + b ) / 2 ; } public static void main ( String [ ] args ) { int a = Integer . MAX_VALUE ; int b = Integer . MAX_VALUE ; System . out . println ( " Actual ▁ average ▁ : ▁ " + Integer . MAX_VALUE ) ; System . out . println ( " Computed ▁ average ▁ : ▁ " + compute_average ( a , b ) ) ; } }