Menu
Question Index
...

Write a program to map the numbers from one list with the neareast smaller number in the other list. If there is no matching smaller number, then do not include that number in the map.

Input (List, List) Map
[500.00, 510.00, 515.00, 520.00, 525.00], [501.00, 511.00, 522.00, 518.00, 525.00] [511.0=510.0, 518.0=515.0, 522.0=520.0, 525.0=520.0, 501.0=500.0]
[500.00, 510.00, 515.00, 520.00, 525.00], [511.00, 512.00, 514.00, 521.00, 527.00, 530.00, 518.00, 523.00] [511.0=510.0, 512.0=510.0, 514.0=510.0, 518.0=515.0, 521.0=520.0, 523.0=520.0, 527.0=525.0, 530.0=525.0]
[100.00, 105.00, 110.00, 119.00, 121.00, 136.00, 144.00], [95.00, 103.00, 150.00, 130.00, 111.00, 129.00, 78.00, 147.00] [129.0=121.0, 111.0=110.0, 103.0=100.0, 130.0=121.0, 147.0=144.0, 150.0=144.0]
[23.00, 50.00, 35.00, 40.00, 39.00, 70.00, 85.00], [100.00, 90.00, 60.00, 83.00, 50.00, 33.00, 23.00, 45.00] [90.0=85.0, 45.0=40.0, 60.0=50.0, 50.0=40.0, 33.0=23.0, 100.0=85.0, 83.0=70.0]
[133.00, 150.00, 500.00, 510.00, 515.00, 199.00], [300.00, 318.00, 200.00, 210.00, 218.00, 250.00, 290.00] [290.0=199.0, 250.0=199.0, 200.0=199.0, 218.0=199.0, 318.0=199.0, 210.0=199.0, 300.0=199.0]


import java.util.*;
class MapToNearestSmallerNumber
{
    public static void main(String s[])
    {
        ArrayList<Double> first = new ArrayList<Double>();
        first.add(500.00);
        first.add(510.00);
        first.add(515.00);
        first.add(520.00);
        first.add(525.00);
        ArrayList<Double> second = new ArrayList<Double>();
        second.add(501.00);
        second.add(511.00);
        second.add(522.00);
        second.add(518.00);
        second.add(525.00);
        HashMap<Double, Double> output = getNearestSmallestNumbers(first, second);
        System.out.println("The resultant map is : ");
        System.out.println(output);

    }


    private static HashMap getNearestSmallestNumbers(List<Double> first, List<Double> second) {
    }

}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App