Menu
Question Index
...

Write a program to get the nearest value from the list of values as explained below.

Input (Double value, List of double values) Output
12.0
[3.0, 23.0, 34.02, 11.23, 56.89, 10.98, 9.78]
23.0
Note: Nearest value of 12.0 is 11.23 and after the nearest value is 23.0(According to ascending order of list like [3.0, 9.78, 10.98, 11.23, 23.0, 34.23, 56.98])
29.00
[-10.23, 12.34, -23.45, 27.00, 31.00, 32.32, 28.55]
31.00
Note: Nearest value of 29.00 is 28.55 and after the nearest is 31.00(According to ascending order of list like [-23.45, -10.23, 12.34, 27.00, 28.55, 31.00, 32.32])
23.00
[20.00, 55.23, 96.23, 34.56, 45.67, 12.34, 44.55]
34.56
Note: Nearest value of 23.00 is 20.00 and after the nearest is 34.56(According to ascending order of list like [12.34, 20.00, 34.56, 44.55, 45.67, 55.23, 96.23])
25.00
[11.0, 11.00, 23.00, 27.00, 29.00, 40.00, 18.00]
27.00
Note: Nearest value of 25.00 is 23.00 and after the nearest is 27.00(According to ascending order of list like [11.0, 11.00, 18.00, 23.00, 27.00, 29.00, 40.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 GetAfterNearestValue
{
    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 = getAfterNearestValue(value, list);
        System.out.println("The value after the nearest value for given value "+value+" from the list of values "+list+" is "+result);

    }


        public static Double getAfterNearestValue(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