Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- static double smallestAbsDiff(double[] a) {
- double mn = 1e9;
- for (int i = 0; i < a.length; i++) {
- for (int j = i + 1; j < a.length; j++) {
- mn = Math.min(mn, Math.abs(a[i] - a[j]));
- }
- }
- return mn;
- }
- public static void main(String[] args) {
- double[] a = {4.5, 3.5, 6, 20, 3};
- System.out.println(smallestAbsDiff(a));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment