数组

public class shuzu {

    public static void main(String []age){
//        int a[]=new int[2];
public class shuzu {
    public static void main(String[] args){
        char a[][]=new char[4][];
        a[0]=new char[]{'春','眠','不','觉','晓'};
        a[1]=new char[]{'处','处','闻','啼','鸟'};
        a[2]=new char[]{'夜','来','风','雨','声'};
        a[3]=new char[]{'花','落','知','多','少'};
    System.out.println("---横版输出---");
        for (int i=0;i<a.length;i++){
            for (int j=0;j<a[i].length;j++){
                System.out.print(a[i][j]);
            }
            if(i%2==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.println(",。,。");
    }
}

//        a[0]=14;
//        a[1]=14;
//        int[] c=new  int[]{4,9,1};
//        System.out.println(c[2]);
//length求数组长度 数组名+.length;length-1是最后一个;并且是int类型的值,length只是常量
//数组长度不可以定义为负值;“一维数组”
//        int a[]={4,5,34,54,58,45,8,5,46,6,544};
//        int max=0;
//        for(int i=0;i<a.length;i++){
//            if (a[i]>max){
//                max=a[i];
//            }
//        }
//        System.out.println(max);
        //二维数组初始化
//        int a[][]=new int[3] [];
//        a[0]=new int[]{56,78,90,11,24,35};
//        a[1]=new int[]{1,2,3};
//        a[2]=new int[]{6,7,8,9};
//       for (int i=0;i<a.length;i++){
//           System.out.print("a["+i+"]中有"+a[i].length+"个元素,分别是");
//           for(int tmp:a[i]){
//               System.out.print(tmp+" ");
//           }
//           //a.length是指多少行;a.length0是指其中有多少列
//           //只能定义行,不能定义列;前面不能空,后面可以空;才能插入数据
//           System.out.println();
//       }
        char a[][]=new char[4][];
     
a[0]=new char[]{'春','眠','不','觉','晓'};
a[1]=new char[]{'处','处','闻','啼','鸟'};
a[2]=new char[]{'夜','来','风','雨','声'};
a[3]=new char[]{'花','落','知','多','少'};
System.out.println("横版输出"); for (int i=0;i<a.length;i++)
{
for (int j=0;j<a[i].length;j++){ System.out.print(a[i][j]);
}

if(i%2==0){
System.out.println(
",");
}
else {
System.out.println(
"。");
}
}
}
}
原文地址:https://www.cnblogs.com/llhhcc/p/9863249.html