PairWise

In this exercise, we are looking for all pairwise multiplications between numbers from a
given list of numbers. In particular, you are given a list of integers. We are then looking
for possible multiplications that can be created by pairs of two out of the given
numbers. For example, when the input list contains the numbers 1, 2 and 3, then the
pairwise multiplications are 2 (1*2 ), 3 ( 1*3 ) and 6 (2*3 ). The found pairwise
multiplications have to be returned in a list.Your program should:
– Take as input a List of numbers
– Return all pairwise multiplications as a List
– Have the following signature:
public static List getPairwiseMultiplications(List
numbers)Moreover, take into account the following when writing your program:
– Each pairwise multiplication of two numbers in the list should be included only
once in the returned list.
– If two pairs of numbers have the same pairwise multiplication, you should include
only one result. For example, when the numbers 2, 3, 4 and 6 are all included in
the input list, then both 2*6 and 3*4 result in 12. However, 12 should be included
only once in the output.
– Your program should be able to handle a list of all sizes as input, even an empty
list or a list with one element. In both these cases, it should return an empty list.
– The order of elements in the output lists is not important, so you can have an
output that contains the same elements but in a different order.
– You can assume that all multiplications can fit into a variable of the int type.

×
New Download