The problem
Write a program that prints characters in a range. This method prints the characters between ch1 and ch2 with the specified numbers per line. Write a test program that prints ten characters per line from 1 to Z. Characters are separated by exactly one space.
Breaking it down
public static void main(String[] args) {
printChars('2', 'c', 10);
}
public static void printChars(char ch1, char ch2, int numberPerLine) {
for (int count = 1; ch1 <= ch2; count++, ch1++) {
System.out.print(ch1 + " ");
if (count % numberPerLine == 0)
System.out.println("");
}
}
Output
2 3 4 5 6 7 8 9 : ;
< = > ? @ A B C D E
F G H I J K L M N O
P Q R S T U V W X Y
Z [ \ ] ^ _ ` a b c