Eclipse で次のコードを入力すると、1 行あたり 10 文字の行が期待されました。しかし、最初と最後の行が3文字しかない理由がわかりません。誰でも助けることができますか?
package chapter4;
import java.util.*;
public class DisplayChars {
public static void printChars(char c1, char c2, int num){
for(int i = (int)c1; i <= (int)c2; i++){
if(i % num == 0)
System.out.println("");
System.out.print((char)i);
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("please enter two characters and the number per line");
char c1 = (char)input.next().charAt(0);
char c2 = (char)input.next().charAt(0);
int numberPerLine = input.nextInt();
printChars(c1, c2, numberPerLine);
}
}
出力は次のとおりです。
please enter two characters and the number per line
a
z
10
abc
defghijklm
nopqrstuvw
xyz