Source: https://www.labunix.uqam.ca/~tremblay_gu/INF5171/Solutions/solutions_java.pdf