0

Below is my implementation of the minimum absolute difference pairs algorithm.

import java.util.*;
public class Greedy{
    public static void main(String args[]){
        int A[]={4,1,8,7};
        int B[]={2,3,6,5};
        Arrays.sort(A);
        Arrays.sort(B);
        int minDiff=0;
        for(int i=0;i<A.length;i++){
            minDiff+=Math.abs(A[i]-B[i]);

        }
        System.out.println("minDiff absolute diff ="+ minDiff);
    }
}

This gives me the error below, however:

Greedy.java:120: error: cannot find symbol
        Arrays.sort(A);
              ^
  symbol:   method sort(int[])
  location: class Arrays
Greedy.java:121: error: cannot find symbol
        Arrays.sort(B);
              ^
  symbol:   method sort(int[])
  location: class Arrays
2 errors

Can anyone identify the error in the code and provide a solution?

Silver Fox
  • 141
  • 8

0 Answers0