Have you tried a for loop: The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)