how to write nested loops in java