Find pair with maximum ratio in an Array | Java implementation to find the maximum pair in the array ; Function to find the maximum pair possible for the array ; Loop to iterate over every possible pair in the array ; Check pair ( x , y ) as well as ( y , x ) for maximum value ; Update the answer ; Driver code
import java . io . * ; import java . util . * ; class GFG { static float computeMaxValue ( float arr [ ] , int n ) { float ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { float val = Math . max ( arr [ i ] / arr [ j ] , arr [ j ] / arr [ i ] ) ; ans = Math . max ( ans , val ) ; } } return ans ; } public static void main ( String [ ] args ) { float arr [ ] = { 15 , 10 , 3 , 2 } ; int N = arr . length ; System . out . println ( computeMaxValue ( arr , N ) ) ; } }