Menu
Question Index
...

Write a program to get the nearest value for a given value from the list of values.

Input (Double value, List of double values) Output
500.0
[501.00, 504.00, 507.00, 511.00, 512.00, 521.00, 523.00]
501.00
12.0
[3.0, 23.0, 34.02, 11.23, 56.89, 10.98, 9.78]
11.23
29.00
[-10.23, 12.34, -23.45, 27.00, 31.00, 32.32, 28.55]
28.55
23.00
[20.00, 55.23, 96.23, 34.56, 45.67, 12.34, 44.55]
20.00
25.00
[11.0, 11.00, 23.00, 27.00, 29.00, 40.00, 18.00]
23.00
12.00
[] {EMPTY LIST}
null
null
[11.0, 11.00, 23.00, 27.00, 29.00, 40.00, 18.00]
null
null
null
null


import java.util.*;
class GetNearestValue
{
    public static void main(String s[])
    {
        Double value = 12.0;
        ArrayList<Double> list = new ArrayList<Double>();
        list.add(3.0);
        list.add(23.0);
        list.add(34.02);
        list.add(11.23);
        list.add(56.89);
        list.add(10.98);
        Double result = getNearestValue(value, list);
        System.out.println("The nearest value for given value "+value+" from the list of values "+list+" is "+result);

    }


        public static Double getNearestValue(Double value, List<Double> list)
        {
            Double result = null;
            return result;
        }

}

Doubts

Problems

Topic: Java Collection Algorithms

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App