Modify array by replacing elements with their farthest co-prime number from a given range

import java.io.*;import java.lang.*;import java.util.*;class GFG{static int gcd(int a, int b){             if (a == 0)        return b;        return gcd(b % a, a);}static void update(int arr[], int n){             for(int i = 0; i < n; i++)    {                                 int d = 0;                        int coPrime = -1;                for(int j = 2; j