Problems 1 to 6 in Java