首页 > 试题广场 >

(显示字符)使用下面的方法头,编写一个打印字符的方法: p

[问答题]
 (显示字符)使用下面的方法头,编写一个打印字符的方法: public static void printChars(char chi, char ch2, int numberPerLine) 该方法打印 ch1到 ch2 之间的字符,每行按指定个数打印。编写一个测试程序,打印 从'1’ 到 'Z' 的字符,每行打印 10 个。字符之间使用一个空格字符隔开。
    public static void printChars(char chi, char ch2, int numberPerLine) {
        int start = chi;
        int end = ch2;
        int count = 0;
        for (int i = start; i <= end; i++) {
            if (count == numberPerLine) {
                System.out.println();
                count = 0;
            }
            System.out.print((char) i + " ");
            count++;
        }
    }

发表于 2021-05-26 14:56:27 回复(0)