输出古诗#java从入门到精通

创建Poetry类,声明一个字符型二维数组,将古诗春晓的内容赋值于二维数组,然后分别用横板和竖版两种方式输出。#Java从入门到精通

如有帮助,请点击我这个回答右上角【采纳】按钮支持一下,谢谢。
代码如下:

public class Poetry {
    private static char[][] chars;
    public static void main(String[] args) {
        chars=new char[][]{{'春','眠','不','觉','晓'},{'处','处','闻','啼','鸟'},{'夜','来','风','雨','声'},{'花','落','知','多','少'}};
        for (int i = 0; i < chars.length; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print(chars[i][j]);
            }
            System.out.print(" ");
        }
        System.out.println("\n================================");
        for (int i = 0; i < chars.length; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print(chars[i][j]);
            }
            System.out.println();
        }
    }
}

img

public static void main(String[] args) {
        // TODO 自动生成的方法存根
        char [][]a=new char[4][];
        a[0]=new char[] {'春','眠','不','觉','晓'};
        a[1]=new char[] {'处','处','闻','啼','鸟'};
        a[2]=new char[] {'夜','来','风','雨','声'};
        a[3]=new char[] {'花','落','知','多','少'};
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print(a[i][j]);
            }
            if (i==0) {
                System.out.println(",");
            } else {
                System.out.println("。");
            }
        }//横版
        System.out.println("------------------");
        for (int j = 0; j < 5; j++) {
            for (int i = 3; i >= 0; i--) {
                System.out.print(a[i][j]);
            }System.out.println("");
        }System.out.print("。,。,");
        //竖版
    }