Menu
Question Index
...

Write a program to measure oil with given cans. Assuming that there is a tank with oil and we have cans in various sizes. Using those cans, we need to measure the required quantity by measuring minimum number of times.

Input (List, int) Output (List)
[1, 2, 4] and 10 [4, 4, 2]
[1, 2, 3] and 20 [3, 3, 3, 3, 3, 3, 2]
[4, 7, 9] and 3 []
[2, 4, 10] and 36 [10, 10, 10, 4, 2]


import java.util.*;
class MeasureOilWithGivenCans
{
    public static void main(String s[])
    {
        List<Integer> cans = new ArrayList<Integer>();
        int quantity = 10;
        cans.add(1);
        cans.add(2);
        cans.add(3);
        System.out.println("Cans used to measure oil are : " + getCans(cans, quantity));

    }


    public static List<Integer> getCans(List<Integer> inputCans, int quantity) {
    }

}

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