There are some chickens and some cows in Farmer John's yard.
John's daughter Susie counted that all the animals in the yard have a total of 3 heads.
John's son Billy counted their legs and got a total of 8.
Using their answers, Farmer John easily determined that there have to be exactly 2 chickens and 1 cow.
Write a method that will solve a general version of Farmer John's problem.
You are given two ints heads and legs. Compute the number of chickens and the number of cows. Return a int[] with two elements: first the number of chickens, then the number of cows. If there is no solution, return an empty int[] instead.
|