Algrithm examples in Java