数组的遍历输出

public class Text { 
    public static void main(String[] args) {
        char[] chArr={'A','B','C'};
        for(int i=0;i<chArr.length;i++)
            System.out.print(chArr[i]+" ");
        //传统的遍历输出方式
        System.out.println();
        for(char i:chArr){
            System.out.print(i+" ");            
        }
        //整体每一个都遍历,用此比较简便
        int[][] arr={{1,2,3},{4,5,6},{7,8,9}};
        for(int i[]:arr){
            for(int j:i)
                System.out.print(j);
            System.out.println();
        }
        //二维数组的遍历输出
        String str="OK";
        String str1="OK";
        System.out.println(str==str1);//结果为true
        
        String str2=new String("OK");
        String str3=new String("OK");
        System.out.println(str2==str3);//结果为false
        System.out.println(str2.equals(str3));//结果为true,比较对象的值

        int[][] arry2d1={{1,3,5},{2,4,6}};
        int[][] arry2d2={{111,3,5},{2,444,6}};       
        int[][][] arry={arry2d1,arry2d2};
        for(int[][] a:arry){
            for(int[] b:a){
                for(int c:b){
                    System.out.print(c+" ");
                }
                System.out.println();
            }
            System.out.println();
        }//三维数组的遍历输出               
    }    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值