Iterate through all pairs
for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { int number = Integer . parseInt ( getNumber ( arr [ i ] , arr [ j ] ) ) ; largest = Math . max ( largest , number ) ; } System . out . println ( largest ) ; }